⌘K

Icon SunFilledIcon MoonStars

Icon LinkAssets

Icon LinkTransferring 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.

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);

Icon LinkList Assets in the Wallet

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

const assets = await fuel.assets();
console.log("Assets ", assets);

Icon LinkAdding custom Assets

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

await fuel.addAssets(assets);

Icon LinkListening to Asset Events

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]);

Icon LinkWith React

In a React app you can use the useAccount hook as shown below to check the account balance for a specific asset.

import { useAccount } from '@fuel-wallet/react';
// ...
const { accountAddress } = useAccount();
 
const { balance } = useBalance({
  address: accountAddress,
  assetId: '0x000000000...',
});
console.log(balance);
// 0004990000