Once the connection is authorized, you can list the user accounts using window.fuel.accounts()
.
1const accounts = await fuel.accounts();
2console.log("Accounts ", accounts);
To listen to account events, you can use the fuel.events.accounts
event.
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]);
You can also get the current account being used in the wallet using window.fuel.currentAccount()
.
1const currentAccount = await fuel.currentAccount();
2console.log("Current Account ", currentAccount);
To listen to current account events, you can use the fuel.events.currentAccount
event.
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]);