Token Transfer
Supports sending CROSS tokens, ERC20 tokens, and custom transactions with metadata.
Send CROSS
Function to transfer native CROSS tokens.
import { useAppKitAccount, SendController } from '@to-nexus/sdk/react'
const RECEIVER_ADDRESS = "0xB09f7E5309982523310Af3eA1422Fcc2e3a9c379"
const SEND_CROSS_AMOUNT = 1
function sendCross() {
const account = useAppKitAccount()
if (!account?.isConnected) return
SendController.sendNativeToken({
receiverAddress: RECEIVER_ADDRESS,
sendTokenAmount: SEND_CROSS_AMOUNT,
decimals: '18'
})
}
Send ERC20
Function to transfer ERC20 tokens.
import { useAppKitAccount, SendController, useAppKitNetwork } from '@to-nexus/sdk/react'
const ERC20_ADDRESS = "0x6892a97F4E85D45f4CaCAfBc5fc0B5186f355A1b"
const RECEIVER_ADDRESS = "0xB09f7E5309982523310Af3eA1422Fcc2e3a9c379"
const SEND_ERC20_AMOUNT = 1
function sendERC20() {
const account = useAppKitAccount()
const network = useAppKitNetwork()
if (!account?.isConnected) return
const ERC20_CAIP_ADDRESS = `${network.caipNetworkId}:${ERC20_ADDRESS}`
SendController.sendERC20Token({
receiverAddress: RECEIVER_ADDRESS,
contractAddress: ERC20_CAIP_ADDRESS,
sendTokenAmount: SEND_ERC20_AMOUNT,
decimals: '18'
})
}
Transaction Status
Functionality to monitor transaction status.
import { useAppKitAccount, SendController } from '@to-nexus/sdk/react'
function sendTransaction() {
const account = useAppKitAccount()
if (!account?.isConnected) return
const resTx = SendController.sendNativeToken({
receiverAddress: RECEIVER_ADDRESS,
sendTokenAmount: 1,
decimals: '18'
})
resTx.on('pending', () => console.log('Pending'))
resTx.on('confirmed', () => console.log('Confirmed'))
resTx.on('failed', () => console.log('Failed'))
}
Gas Estimation
Functionality to estimate gas fees before sending a transaction.
import { useAppKitAccount, ConnectionController } from '@to-nexus/sdk/react'
function GasEstimator() {
// Get account state
const account = useAppKitAccount()
// Handle gas estimation
async function estimateGas() {
// Check if wallet is connected
if (!account?.isConnected) {
alert('Please connect wallet first.')
return
}
// Estimate gas for ERC20 transfer
const gasEstimate = await ConnectionController.estimateGas({
contractAddress: ERC20_ADDRESS,
method: 'transfer',
abi: sampleErc20ABI,
args: [RECEIVER_ADDRESS, SEND_ERC20_AMOUNT_IN_WEI]
})
console.log('Estimated gas:', gasEstimate)
}
return <button onClick={estimateGas}>Estimate Gas</button>
}
Updated 21 days ago