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 | number | The amount to transfer |
- Web
- Flutter
const tokenAddress = "YOUR_TOKEN";
const to = "RECEIVER_ADDRESS";
const amount = parseEther("0.001");
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();