To transfer a specific amount to another address, use the wallet.transfer() method.
// Retrieve the current account addressconst account =await fuel.currentAccount();// If the current account is null this means the user has not authorized// the currentAccount to the connection.if (!account) {thrownewError("Current account not authorized for this connection!");}// Create a Wallet instance from the current accountconst wallet =await fuel.getWallet(account);// Create a Address instance to the receiver addressconst toAddress = Address.fromString(receiverAddress);// Get the minGasPrice and maxGasPerTx for the networkconst { minGasPrice } =await wallet.provider.getGasConfig();// Send a transaction to transfer the asset to the receiver addressconst response =await wallet.transfer(toAddress, amount, assetId, { gasPrice: minGasPrice, gasLimit:5_000,});console.log("Transaction created!", response.id);
To transfer an amount to other address, use the wallet.transfer() method and pass in the address you want to send to and the amount to send as well as the assetId.
const { wallet } =useWallet(); // or useAccount(address);asyncfunctiontransfer(amount:BN, receiverAddress:string, assetId:string) {if (!wallet) {thrownewError("Wallet not found!"); }// Create a Address instance to the receiver addressconst toAddress = Address.fromString(receiverAddress);// Get the minGasPrice and maxGasPerTx for the networkconst { minGasPrice } =await wallet.provider.getGasConfig();// Send a transaction to transfer the asset to the receiver addressconst response =await wallet.transfer(toAddress, bn(amount), assetId, { gasPrice: minGasPrice, gasLimit:5_000, }); console.log("Transaction created!", response.id);}