Examples
Get balance for all wallets
In this example, we will get the balance for each connect wallet.
For each wallet, we will get the provider with rpcProvider
, to fetch the
balance by calling the getBalance
with the wallet address.
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
const App = () => {
const { connectedWallets } = useDynamicContext();
useEffect(() => {
connectedWallets.forEach(async (wallet) => {
if (!wallet) return;
// Get the configured rpc proivder
const provider = rpcProviders.evmDefaultProvider?.provider;
if (!provider) return;
// Fetch the wallet balance
const balance = await provider.getBalance(wallet.address);
console.log('balance', balance.toString());
});
}, [connectedWallets]);
...
}
Was this page helpful?