SDK
Javascript
How to
Wallet Operation
Send Token

Send Token

This method allows you to send tokens (ERC20) from a blockchain network.

Method Signature

async sendToken(config: SendTokenConfig): Promise<TransactionReceipt>

Parameters

config: SendTokenConfig - An object with the following properties:

  • network: Network (required) - The network used for transactions.
  • to: string (required) - The address of the recipient.
  • amount: string (required) - The amount of the transaction.
  • tokenAddress: string (required) - The address of the token user wants to send.
  • nonce: string (optional) - The number used once to prevent duplicate transactions (this will be calculated automatically if not provided).
  • gasPrice: string (optional) - Gas price in Wei (this will be calculated automatically if not provided).
  • gasLimit: string (optional) - Gas limit for single transaction, transaction will be reverted if actual gas consumption is higher than gas limit (this will be calculated automatically if not provided).
  • maxPriorityFeePerGas: string (optional) - Maximum priority fee per gas you are willing to pay, this only used in EIP1559 support blockchain.

Returns

Promise<TransactionReceipt> - An object containing the transaction receipt data.

Example Usage

const receipt = await sdk.wallet.sendToken({
  network: Network.ETHEREUM,
  to: '0x1234567890123456789012345678901234567890',
  amount: '0.123',
  tokenAddress: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
});
console.log(receipt);

Response Example

{
  "txReceipt": {
    "_type": "TransactionReceipt",
    "accessList": null,
    "blockNumber": null,
    "blockHash": null,
    "chainId": "1",
    "data": "0xa9059cbb000000000000000000000000bfe64b4b628e0998a03e2522b051cf1b4661c9640000000000000000000000000000000000000000000000008ac7230489e80000",
    "from": "0xBfE64B4b628E0998A03e2522B051Cf1B4661c964",
    "gasLimit": "51580",
    "gasPrice": "10000000000",
    "hash": "0x6cfad4fd9f3aae8e3c3d9e79f3bee3c4b467086a995a1bfd20c7a821a32365cb",
    "maxFeePerGas": null,
    "maxPriorityFeePerGas": null,
    "nonce": 1,
    "signature": {
      "_type": "signature",
      "networkV": "229",
      "r": "0x7e0f60d0d2c7e71a707212ecb74744252e799aed281a6849fe227256dafefb38",
      "s": "0x58f5cebba1142015b5f92d5124d49b15126e00a5f210b2780418e75c79b041dc",
      "v": 27
    },
    "to": "0x9B9ef330B204bf33316FAf24E3Ed4FfCf57F02C3",
    "type": 0,
    "value": "0"
  }
}
ℹ️

The response is an object containing the transaction receipt data, including details such as the transaction hash, gas used, and block information.

Additional Information

  • This method requires a valid wallet token in the SDK configuration.
  • The amount parameter should be provided as a string to preserve precision for large numbers.
  • The tokenAddress parameter should be the contract address of the ERC20 token you want to send.
  • Optional parameters like nonce, gasPrice, and gasLimit will be automatically calculated if not provided.
  • For EIP1559 compatible networks, you can specify maxPriorityFeePerGas.

For more information, see the Xellar Send Token API Documentation (opens in a new tab).