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
| Name | Type | Default |
|---|---|---|
connection | ConnectionSolana connection instance for blockchain interaction. | |
wallet | SignerWalletThe wallet instance with signing capabilities. | |
mint | stringThe mint address of the token to transfer. | |
amount | bigint | string | numberAmount in base token units. | |
destination | stringThe destination wallet address for the transfer. | |
config | TransferConfigOptions such as logging, retries, timeouts, simulation, and ATA creation. | |
TransferConfig
| Name | Type | Default |
|---|---|---|
createDestinationATA | booleanWhether to create a destination ATA for the token to be transferred. | |
OperationConfig | OperationConfigThe base operation for any transaction in Okito. | |
Response
| Name | Type | Default |
|---|---|---|
OperationResult | OperationResultThe result of the token transfer. | |
createdDestinationATA | booleanWhether a destination ATA was created for the token transfer. | |
Last updated on