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.
const accounts = await fuel.accounts();
const account = accounts[0];
const wallet = await fuel.getWallet(account);
const toAddress = Address.fromString(addr);
const gasConfig = await getGasConfig(wallet.provider);
const response = await wallet.transfer(toAddress, amount, assetId, {
...gasConfig,
});
console.log("Transaction created!", response.id);
You can list the assets in the wallet using window.fuel.assets()
.
const assets = await fuel.assets();
console.log("Assets ", assets);
To add custom Assets, use the wallet.addAssets
method and pass in the Asset[]
you want to add.
await fuel.addAssets(assets);
To listen to asset events, you can use the fuel.events.assets
event.
const handleAssetsEvent = (assets: Asset[]) => {
setAssets(assets);
};
useEffect(() => {
fuel?.on(fuel.events.assets, handleAssetsEvent);
return () => {
fuel?.off(fuel.events.assets, handleAssetsEvent);
};
}, [fuel]);