Docs Icon ChevronRight For Developers Icon ChevronRight Accounts

Accounts

List user accounts

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

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

Watch Account Changes

To watch account events, you can use the accounts event.

Accounts.tsx Icon Link
1function logAccounts(accounts: string) {
2  console.log("Accounts ", accounts);
3}
4fuel.on(fuel.events.accounts, logAccounts);

Get Current Account

You can also get the current account being used in the wallet using currentAccount(). If the return is null this means that the current account selected by the user is not connected.

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

Watch Current Account Changes

To monitor events related to the current account, utilize the currentAccount event. Receiving a null value from this event indicates that the user's currently selected account is not connected. If the event receive a null value this means that the current account selected by the user is not connected.

CurrentAccount.tsx Icon Link
1function logCurrentAccount(account: string) {
2  console.log("Current Account ", account);
3}
4fuel.on(fuel.events.currentAccount, logCurrentAccount);

With React

You can keep track of the current account when using React using the useAccount hook as shown below:

All Connected Accounts

AccountsHook.tsx Icon Link
1const { accounts } = useAccounts();

Current Account

CurrentAccountHook.tsx Icon Link
1const { account } = useAccount();