- React
 - React Native
 
For each wallet, we will get the provider with useRpcProviders, to fetch the
balance by calling the 
getBalance with the wallet address.In this example, we will get the balance for each connected wallet.
getBalance with the wallet address.import { useUserWallets } from '@dynamic-labs/sdk-react-core';
import { useRpcProviders } from '@dynamic-labs/sdk-react-core'
import { evmProvidersSelector } from '@dynamic-labs/ethereum-core'
const App = () => {
  const userWallets = useUserWallets();
  const { defaultProvider } = useRpcProviders(evmProvidersSelector)
  useEffect(() => {
    userWallets.forEach(async (wallet) => {
      if (!wallet) return;
      // Get the EVM Mainnet provider
     const provider = defaultProvider?.provider;
      if (!provider) return;
      // Fetch the wallet balance
      const balance = await provider.getBalance({ address: wallet.address });
      console.log('balance', balance.toString());
    });
  }, [userWallets, defaultProvider]);
  ...
}
Was this page helpful?