Token Transfer
Supports sending CROSS tokens, ERC20 tokens, and custom transactions with metadata.
Send CROSS
Function to transfer native CROSS tokens.
// React Example
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'
})
}
// Vanilla JS Example
import { SendController, ConstantsUtil } from '@to-nexus/sdk';
const RECEIVER_ADDRESS = '0xB09f7E5309982523310Af3eA1422Fcc2e3a9c379';
const SEND_CROSS_AMOUNT = 1;
const resTx = await SendController.sendNativeToken({
data: '0x',
receiverAddress: RECEIVER_ADDRESS,
sendTokenAmount: SEND_CROSS_AMOUNT, // in eth (not wei)
decimals: '18',
customData: {
metadata: 'You are about to send 1 CROSS to the receiver address. This is plain text formatted custom data.'
},
type: ConstantsUtil.TRANSACTION_TYPE.LEGACY
});
Send ERC20
Function to transfer ERC20 tokens.
// React Example
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'
})
}
// Vanilla JS Example
import { SendController, ConstantsUtil } from '@to-nexus/sdk';
const RECEIVER_ADDRESS = '0xB09f7E5309982523310Af3eA1422Fcc2e3a9c379';
const ERC20_ADDRESS = '0xe934057Ac314cD9bA9BC17AE2378959fd39Aa2E3';
const networkState = /* your network state */;
const ERC20_CAIP_ADDRESS = `${networkState.caipNetworkId}:${ERC20_ADDRESS}`;
const SEND_ERC20_AMOUNT = 1;
const resTx2 = await SendController.sendERC20Token({
receiverAddress: RECEIVER_ADDRESS,
contractAddress: ERC20_CAIP_ADDRESS,
sendTokenAmount: SEND_ERC20_AMOUNT, // in eth (not wei)
decimals: '18',
customData: {
metadata: `<DOCTYPE html><html><head><title>Game Developer can add custom data to the transaction</title></head><body><h1>Game Developer can add custom data to the transaction</h1><p>This is a HTML text formatted custom data.</p></body></html>`
},
type: ConstantsUtil.TRANSACTION_TYPE.LEGACY
});
Transaction Status
Functionality to monitor transaction status.
// React Example
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'))
}
// Vanilla JS Example
const resTx = await SendController.sendNativeToken({
data: '0x',
receiverAddress: RECEIVER_ADDRESS,
sendTokenAmount: 1,
decimals: '18',
customData: {
metadata: 'You are about to send 1 CROSS to the receiver address. This is plain text formatted custom data.'
},
type: ConstantsUtil.TRANSACTION_TYPE.LEGACY
});
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.
// React Example
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>
}
// Vanilla JS Example
import { ConnectionController } from '@to-nexus/sdk';
const ERC20_ADDRESS = '0xe934057Ac314cD9bA9BC17AE2378959fd39Aa2E3';
const sampleErc20ABI = /* ... ABI ... */;
const RECEIVER_ADDRESS = '0xB09f7E5309982523310Af3eA1422Fcc2e3a9c379';
const SEND_ERC20_AMOUNT_IN_WEI = /* use parseUnits if needed */;
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);
Updated about 19 hours ago