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