Docs Icon ChevronRight For Developers Icon ChevronRight Accounts

Accounts

List user accounts

Once the connection is authorized, you can list the user accounts using window.fuel.accounts().

ListAccounts.tsx Icon Link
1const accounts = await fuel.accounts();
2console.log("Accounts ", accounts);

Listening to Account Changes

To listen to account events, you can use the fuel.events.accounts event.

Accounts.tsx Icon Link
1const handleAccountsEvent = (accounts: string[]) => {
2  setAccounts(accounts);
3};
4
5useEffect(() => {
6  fuel?.on(fuel.events.accounts, handleAccountsEvent);
7  return () => {
8    fuel?.off(fuel.events.accounts, handleAccountsEvent);
9  };
10}, [fuel]);

Get Current Account

You can also get the current account being used in the wallet using window.fuel.currentAccount().

CurrentAccount.tsx Icon Link
1const currentAccount = await fuel.currentAccount();
2console.log("Current Account ", currentAccount);

Listening to Current Account Changes

To listen to current account events, you can use the fuel.events.currentAccount event.

CurrentAccount.tsx Icon Link
1const handleAccountEvent = (account: string) => {
2  setCurrentAccount(account);
3};
4
5useEffect(() => {
6  // listen to the current event account, and call the handleAccountEvent
7  fuel?.on(fuel.events.currentAccount, handleAccountEvent);
8  return () => {
9    // remove the listener when the component is unmounted
10    fuel?.off(fuel.events.currentAccount, handleAccountEvent);
11  };
12}, [fuel]);