Docs Icon ChevronRight For Developers Icon ChevronRight Assets

Assets

Transferring assets

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.

Transfer.tsx Icon Link
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);

List Assets in the Wallet

You can list the assets in the wallet using window.fuel.assets().

ListAssets.tsx Icon Link
1const assets = await fuel.assets();
2console.log("Assets ", assets);

Adding custom Assets

To add custom Assets, use the wallet.addAssets method and pass in the Asset[] you want to add.

AddAssets.tsx Icon Link
1await fuel.addAssets(assets);

Listening to Asset Events

To listen to asset events, you can use the fuel.events.assets event.

Assets.tsx Icon Link
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]);