Intents

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

Ethereum
Ethereum
Polygon
Polygon
Solana
Solana
Aptos
Aptos
Avalanche
Avalanche
Arbitrum
Arbitrum
BSC
BSC
Fantom
Fantom
Linea
Linea
Metis
Metis
Optimism
Optimism
Base
Base
Base Sepolia
Base Sepolia
HyperEVM Testnet
HyperEVM Testnet
Polygon Amoy
Polygon Amoy

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:

Method Overview

MethodDescription
async tokenTransferCreate a user operation for token transfer

Token Transfer

async tokenTransfer(oktoClient: OktoClient, data: TokenTransferIntentParams) creates a user operation for transferring tokens.

Parameters

ParameterTypeDescriptionRequired
oktoClientOktoClientInstance of OktoClient obtained from useOkto hookYes
dataTokenTransferIntentParamsParameters for the token transferYes
feePayerAddressstringAddress of the Treasury Wallet responsible for covering gas fees when sponsorship is enabledOptional

Where TokenTransferIntentParams contains:

FieldTypeDescriptionRequired
amountnumber | bigintAmount to send, in the smallest unit (e.g., gwei for ETH)Yes
recipientAddressWallet address of the recipientYes
tokenAddress | ''The token address for the transactionYes
caip2IdstringThe network ID (e.g., Ethereum - eip155:1, Polygon - eip155:137)Yes

Response

Success Response

Field NameTypeDescription
resultPromise<string>Returns the jobId for the token transfer

Success Response

Field NameTypeDescription
resultPromise<UserOp>Returns the user operation for the token transfer