Skip to Content
FunctionsTokentransferTokens

transferTokens

This function transfers SPL tokens from one address to another.

Usage

page.tsx
import { useConnection } from "@solana/wallet-adapter-react"; import { transferTokens } from "@okito/sdk"; const {connection} = useConnection(); const wallet = useWallet(); // Basic usage const result = await transferTokens(connection, wallet, mint, amount, destination); // Production usage with enhanced configuration const productionResult = await transferTokens(connection, wallet, mint, amount, destination, { enableLogging: true, // Detailed operation tracking enableSimulation: true, // Pre-flight transaction testing enableMetrics: true, // Performance monitoring createDestinationATA: true, // Auto-create token accounts strictValidation: true, // Enhanced input validation maxRetries: 3, // Automatic retry on failure timeoutMs: 90000, // 1.5-minute timeout confirmationStrategy: 'confirmed' }); // Transfer with human-readable amounts (convenience function) const decimalResult = await transferTokensWithDecimals( connection, wallet, mint, 10.5, destination // 10.5 tokens );

Capabilities

  • Balance checks with clear feedback
  • Automatic ATA creation when needed
  • Optional pre-flight simulation
  • Support for bigint, string, or number amounts
  • Timing and basic metrics for insight

Parameters

NameTypeDefault
connection
Connection
Solana connection instance for blockchain interaction.
wallet
SignerWallet
The wallet instance with signing capabilities.
mint
string
The mint address of the token to transfer.
amount
bigint | string | number
Amount in base token units.
destination
string
The destination wallet address for the transfer.
config
TransferConfig
Options such as logging, retries, timeouts, simulation, and ATA creation.
Defaults

TransferConfig

NameTypeDefault
createDestinationATA
boolean
Whether to create a destination ATA for the token to be transferred.
OperationConfig
OperationConfig
The base operation for any transaction in Okito.
-

Response

NameTypeDefault
OperationResult
OperationResult
The result of the token transfer.
createdDestinationATA
boolean
Whether a destination ATA was created for the token transfer.
Last updated on