Send Native/ERC20 Transactions
To transfer an ERC20/FUSE with a relay, use the transferToken()
method. This method relays the transaction and covers the gas fees for the user, so they don't need to worry about those fees.
You can also subscribe to events related to the token transfer to track its progress. The method takes the following parameters as inputs:
Parameter | Type | Description |
---|---|---|
tokenAddress | address | The contract address of the ERC20 token or FUSE |
recipientAddress | address | The recipient's wallet address |
amount | string | The amount of tokens to transfer in wei |
- Web
- Flutter
const tokenAddress = "0x28C3d1cD466Ba22f6cae51b1a4692a831696391A"; // USDC Token address
const to = "RECEIVER_ADDRESS";
const amount = parseUnits("0.001", 6); // 6 represents the decimals of USDC token in the [contract](https://explorer.fuse.io/address/0x28C3d1cD466Ba22f6cae51b1a4692a831696391A?tab=read_contract)
const res = await fuseSDK.transferToken(tokenAddress, to, amount);
console.log(`UserOpHash: ${res?.userOpHash}`);
console.log("Waiting for transaction...");
const receipt = await res?.wait();
console.log("Transaction Hash:", receipt?.transactionHash);
final res = await fuseSDK.transferToken(
EthereumAddress.fromHex('TOKEN_ADDRESS'), // For sending native token, use '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
EthereumAddress.fromHex('RECIPIENT_ADDRESS'),
BigInt.parse('AMOUNT_IN_WEI'),
);
print('UserOpHash: ${res.userOpHash}');
print('Waiting for transaction...');
final ev = await res.wait();