Token Transfer
Learn how to create token transfer operations using the Okto React Native SDK.
The tokenTransfer()
function creates a user operation for transferring tokens. This function initiates the process of transferring a token by encoding the necessary parameters into a User Operation, which can then be signed and executed using the OktoClient.
Available on





To enable these chains for your application, please configure them in the Okto Dashboard.
Not available on
There are two ways to implement token transfers:
- Abstracted Flow: A simplified approach where the user operation is automatically created, signed, and executed in a single step. Perfect for most applications.
- UserOp Flow: A granular approach where you manually control the creation, signing, and execution of the user operation. Useful for custom implementations or advanced use cases.
If sponsorship is enabled for your user, you must pass the feePayerAddress
(i.e., the Treasury Wallet address) as a parameter to the intent function. Refer to the example below for implementation details.
Example
import { useOkto } from '@okto_web3/react-native-sdk';
import { tokenTransfer } from '@okto_web3/react-native-sdk';
import { TouchableOpacity, Text, View } from 'react-native';
function TokenTransfer() {
const oktoClient = useOkto();
async function handleTokenTransfer() {
try {
const transferParams = {
amount: BigInt("1000000000000000000"), // 1 token with 18 decimals
recipient: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
token: "0x2170ed0880ac9a755fd29b2688956bd959f933f8", // Token contract address
caip2Id: "eip155:1"
};
const feePayerAddress = "0xdb9B5..." // feePayerAddress used when sponsorship is available
// Execute the transfer
const jobId = await tokenTransfer(oktoClient, transferParams, feePayerAddress?);
console.log('Transfer jobId:', jobId);
} catch (error:any) {
console.error('Error in token transfer:', error);
}
}
return (
<TouchableOpacity onPress={handleTokenTransfer}>
<Text>Transfer Token</Text>
</TouchableOpacity>
);
}
import { useOkto } from '@okto_web3/react-native-sdk';
import { tokenTransfer } from '@okto_web3/react-native-sdk/userop';
import { TouchableOpacity, Text, View } from 'react-native';
function TokenTransfer() {
const oktoClient = useOkto();
async function handleTokenTransfer() {
try {
const transferParams = {
amount: BigInt("1000000000000000000"), // 1 token with 18 decimals
recipient: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
token: "0x2170ed0880ac9a755fd29b2688956bd959f933f8", // Token contract address
caip2Id: "eip155:1"
};
const feePayerAddress = "0xdb9B5..." // feePayerAddress used when sponsorship is available
// Create the user operation
const userOp = await tokenTransfer(oktoClient, transferParams, feePayerAddress?);
// Sign the operation
const signedOp = await oktoClient.signUserOp(userOp);
// Execute the transfer
const jobId = await oktoClient.executeUserOp(signedOp);
console.log('Transfer jobId:', jobId);
} catch (error:any) {
console.error('Error in token transfer:', error);
}
}
return (
<TouchableOpacity onPress={handleTokenTransfer}>
<Text>Transfer Token</Text>
</TouchableOpacity>
);
}
Note
For error handling:
- Use the error code to debug issues. Check out the SDK errors and warnings documentation
- For help, navigate to the troubleshooting guide to contact support
Method Overview
Method | Description |
---|---|
async tokenTransfer | Create a user operation for token transfer |
Token Transfer
async tokenTransfer(oktoClient: OktoClient, data: TokenTransferIntentParams)
creates a user operation for transferring tokens.
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
oktoClient | OktoClient | Instance of OktoClient obtained from useOkto hook | Yes |
data | TokenTransferIntentParams | Parameters for the token transfer | Yes |
feePayerAddress | string | Address of the Treasury Wallet responsible for covering gas fees when sponsorship is enabled | Optional |
Where TokenTransferIntentParams
contains:
Field | Type | Description | Required |
---|---|---|---|
amount | number | bigint | Amount to send, in the smallest unit (e.g., gwei for ETH) | Yes |
recipient | Address | Wallet address of the recipient | Yes |
token | Address | '' | The token address for the transaction | Yes |
caip2Id | string | The network ID (e.g., Ethereum - eip155:1, Polygon - eip155:137) | Yes |
Response
Success Response
Field Name | Type | Description |
---|---|---|
result | Promise<string> | Returns the jobId for the token transfer |
Success Response
Field Name | Type | Description |
---|---|---|
result | Promise<UserOp> | Returns the user operation for the token transfer |