Skip to content

Commit

Permalink
Merge pull request #181 from okto-hq/main
Browse files Browse the repository at this point in the history
raw read for sdks
  • Loading branch information
oviawork authored Dec 7, 2024
2 parents 52e73b6 + 06516e0 commit f5d48b9
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 1 deletion.
5 changes: 5 additions & 0 deletions content/docs/react-native-sdk/advanced-sdk-config/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ Below is an overview of the available functions and their respective purposes.
| [`transferTokens(data)`](/docs/react-native-sdk/advanced-sdk-config/okto-embedded-wallet/use-user-embedded-wallet/transfer-tokens#transfer-tokens) | Transfer tokens based on the provided data |
| [`transferTokensWithJobStatus(data)`](/docs/react-native-sdk/advanced-sdk-config/okto-embedded-wallet/use-user-embedded-wallet/transfer-tokens#transfer-tokens-with-job-status) | Transfer tokens and provides job status updates based on the provided data |

## Read From Contract
| Function | Description |
|----------|-------------|
| [`readContractData(network_name, data)`](/docs/react-native-sdk/advanced-sdk-config/okto-embedded-wallet/use-user-embedded-wallet/read-contract-data#read-contract-data) | Read data from any smart contract on supported chains |

## Raw Transactions
| Function | Description |
|----------|-------------|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"!using-nfts-okto-lite",
"transfer-nfts",
"raw-transactions",
"read-contract-data",
"!read-any-chain-data",
"!read-from-any-contract"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
---
title: Read Contract Data On-chain Via Code
description: Learn how to read data from any smart contract using the Okto SDK.
full: false
---

import { TypeTable } from 'fumadocs-ui/components/type-table';
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
import { Callout } from 'fumadocs-ui/components/callout';
import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
import { Icon as IIcon } from '@iconify/react';

import '../../../styles.css';

### Methods Overview

| Methods | Description |
|---------|-------------|
| <sub><i>async</i></sub> [`readContractData`](#read-contract-data) | Read data from any smart contract on supported chains |

<div className="method-box">

## Read Contract Data

<sub><i>async</i></sub> `readContractData(network_name, data)`<a href="https://github.com/okto-hq/okto-sdk-react-native/blob/bb8b72a0ac41d6f95e3ed37f858700b7b4b668ff/src/OktoWallet.ts#L524" target="_blank" rel="noopener noreferrer" style={{ textDecoration: "none" }}> <IIcon icon="lucide:external-link" height="17" style={{ display: 'inline-block', verticalAlign: 'middle' }} /></a> reads data from a smart contract based on the provided parameters.

### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `network_name` | `string` | The network where the contract is deployed |
| `data` | `any` | Network-specific contract interaction details |

The structure of `data` parameter varies based on the network:

<Tabs items={['EVM', 'Aptos']}>
<Tab value="EVM">
```typescript
// For EVM networks (POLYGON, POLYGON_TESTNET_AMOY, etc.), data should contain:
{
contractAddress: string; // The address of the smart contract
abi: any; // The ABI of the specific function you want to call
args: Record<string, any>; // Arguments for the contract function (empty object if no arguments required)
}
```
</Tab>
<Tab value="Aptos">
```typescript
// For Aptos networks, data should contain:
{
function: string; // The full function path to call
typeArguments: string[]; // Type arguments for the function
functionArguments: string[]; // Arguments to pass to the function
}
```
</Tab>
</Tabs>

### Response

<Callout title="Success Response">

| Field Name | Type | Description |
|------------|------|-------------|
| `result` | `Promise<any>` | Returns the data read from the contract. Type depends on the contract function being called |

</Callout>

<Accordions>
<Accordion title="Example">
<Tabs items={['EVM', 'Aptos']}>
<Tab value="EVM">
```typescript
import { useOkto, type OktoContextType } from 'okto-sdk-react-native';

const { readContractData } = useOkto() as OktoContextType;

const networkName = "POLYGON";
const contractData = {
contractAddress: "0x3BA4c387f786bFEE076A58914F5Bd38d668B42c3",
abi: {
inputs: [],
name: "totalSupply",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
args: {}
};

readContractData(networkName, contractData)
.then((result) => {
console.log('Contract data:', result);
})
.catch((error) => {
console.log('Error reading contract:', error);
});
```
</Tab>
<Tab value="Aptos">
```typescript
import { useOkto, type OktoContextType } from 'okto-sdk-react-native';

const { readContractData } = useOkto() as OktoContextType;

const networkName = "APTOS_TESTNET";
const contractData = {
function: "0x1::chain_id::get",
typeArguments: [],
functionArguments: []
};

readContractData(networkName, contractData)
.then((result) => {
console.log('Contract data:', result);
})
.catch((error) => {
console.log('Error reading contract:', error);
});
```
</Tab>
</Tabs>
</Accordion>
</Accordions>

</div>
6 changes: 6 additions & 0 deletions content/docs/react-sdk/advanced-sdk-config/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ Below is an overview of the available functions and their respective purposes.
| [`transferTokens(data)`](/docs/react-sdk/advanced-sdk-config/okto-embedded-wallet/use-user-embedded-wallet/transfer-tokens#transfer-tokens) | Transfer tokens based on the provided data |
| [`transferTokensWithJobStatus(data)`](/docs/react-sdk/advanced-sdk-config/okto-embedded-wallet/use-user-embedded-wallet/transfer-tokens#transfer-tokens-with-job-status) | Transfer tokens and provides job status updates based on the provided data |

## Read From Contract
| Function | Description |
|----------|-------------|
| [`readContractData(network_name, data)`](/docs/react-sdk/advanced-sdk-config/okto-embedded-wallet/use-user-embedded-wallet/read-contract-data#read-contract-data) | Read data from any smart contract on supported chains |


## Raw Transactions
| Function | Description |
|----------|-------------|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"!using-nfts-okto-lite",
"transfer-nfts",
"raw-transactions",
"read-contract-data",
"!read-any-chain-data",
"!read-from-any-contract"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
---
title: Read Contract Data On-chain Via Code
description: Learn how to read data from any smart contract using the Okto SDK.
full: false
---

import { TypeTable } from 'fumadocs-ui/components/type-table';
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
import { Callout } from 'fumadocs-ui/components/callout';
import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
import { Icon as IIcon } from '@iconify/react';

import '../../../styles.css';

### Methods Overview

| Methods | Description |
|---------|-------------|
| <sub><i>async</i></sub> [`readContractData`](#read-contract-data) | Read data from any smart contract on supported chains |

<div className="method-box">

## Read Contract Data

<sub><i>async</i></sub> `readContractData(network_name, data)`<a href="https://github.com/okto-hq/okto-sdk-react/blob/main/src/OktoProvider.tsx#L589" target="_blank" rel="noopener noreferrer" style={{ textDecoration: "none" }}> <IIcon icon="lucide:external-link" height="17" style={{ display: 'inline-block', verticalAlign: 'middle' }} /></a> reads data from a smart contract based on the provided parameters.

### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `network_name` | `string` | The network where the contract is deployed |
| `data` | `any` | Network-specific contract interaction details |

The structure of `data` parameter varies based on the network:

<Tabs items={['EVM', 'Aptos']}>
<Tab value="EVM">
```typescript
// For EVM networks (POLYGON, POLYGON_TESTNET_AMOY, etc.), data should contain:
{
contractAddress: string; // The address of the smart contract
abi: any; // The ABI of the specific function you want to call
args: Record<string, any>; // Arguments for the contract function (empty object if no arguments required)
}
```
</Tab>
<Tab value="Aptos">
```typescript
// For Aptos networks, data should contain:
{
function: string; // The full function path to call
typeArguments: string[]; // Type arguments for the function
functionArguments: string[]; // Arguments to pass to the function
}
```
</Tab>
</Tabs>

### Response

<Callout title="Success Response">

| Field Name | Type | Description |
|------------|------|-------------|
| `result` | `Promise<any>` | Returns the data read from the contract. Type depends on the contract function being called |

</Callout>

<Accordions>
<Accordion title="Example">
<Tabs items={['EVM', 'Aptos']}>
<Tab value="EVM">
```typescript
import { useOkto, type OktoContextType } from 'okto-sdk-react';

const { readContractData } = useOkto() as OktoContextType;

const networkName = "POLYGON";
const contractData = {
contractAddress: "0x3BA4c387f786bFEE076A58914F5Bd38d668B42c3",
abi: {
inputs: [],
name: "totalSupply",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
args: {}
};

readContractData(networkName, contractData)
.then((result) => {
console.log('Contract data:', result);
})
.catch((error) => {
console.log('Error reading contract:', error);
});
```
</Tab>
<Tab value="Aptos">
```typescript
import { useOkto, type OktoContextType } from 'okto-sdk-react';

const { readContractData } = useOkto() as OktoContextType;

const networkName = "APTOS_TESTNET";
const contractData = {
function: "0x1::chain_id::get",
typeArguments: [],
functionArguments: []
};

readContractData(networkName, contractData)
.then((result) => {
console.log('Contract data:', result);
})
.catch((error) => {
console.log('Error reading contract:', error);
});
```
</Tab>
</Tabs>
</Accordion>
</Accordions>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Follow the steps below to get started quickly with building an Okto-powered Next

```bash title=".env.local"
GOOGLE_CLIENT_ID = "YOUR_GOOGLE_CLIENT_ID"
GOOGLE_CLIENT_SECRET = "YOUR_OKTO_CLIENT_API_KEY"
GOOGLE_CLIENT_SECRET = "YOUR_GOOGLE_CLIENT_SECRET"

# Add these Next-Auth configurations
AUTH_SECRET = "generate-a-secret-key" # Use: openssl rand -base64 32
Expand Down

0 comments on commit f5d48b9

Please sign in to comment.