Token Transfer
This guide explains how to implement token transfers using the Cross Unity SDK.
1. Send Cross Coin
Send CROSS coin from the connected wallet to the recipient wallet address. When the function is called, the signing process will proceed in the wallet.
const string toAddress = "0x920A31f0E48739C3FbB790D992b0690f7F5C42ea"; // recipient address
const value = Web3.Convert.ToWei(1); // convert to wei to send 1 CROSS
var result = await CrossSdk.Evm.SendTransactionAsync(toAddress, value, null, null); // data or custom data can be null
2. Send ERC20 Token
Send a specific ERC-20 token from the connected wallet to the recipient wallet address. When the function is called, the signing process will proceed in the wallet.
const string toAddress = "0x920A31f0E48739C3FbB790D992b0690f7F5C42ea"; // recipient address
const string ERC20_ADDRESS = "0x88f8146EB4120dA51Fc978a22933CbeB71D8Bde6"; // ERC20 token contract address
TextAsset abiText = Resources.Load<TextAsset>("Contracts/SampleERC20abi"); // JSON formatted abi for the token contract file
string abi = abiText.text;
var value = Web3.Convert.ToWei(1);
// Call any contract method with arbitrary parameters
// In this example, WriteContractAsync executes the 'transfer' method
var result = await CrossSdk.Evm.WriteContractAsync(
ERC20_ADDRESS, // contract address
abi, // abi
"transfer", // contract method name
null, // custom data can be null
toAddress,
value
);
Updated 10 days ago