EVM Interactions
Get balance for all wallets
The Basics
- Add Login / Signup
- Chains / Networks
- Wallets
- Set Up Embedded Wallets
- Set Up Branded Wallets
- Smart Wallets
- Using Wallets
- Accessing Wallets
- Interacting with wallets
- General Interactions
- EVM Interactions
- Bitcoin Interactions
- Solana Interactions
- Multi Wallet
- Multi Asset UI
- Send Assets
- Users / VC's
- Design
- Onramps
Beyond The Basics
- Headless
- Global Wallets
- Bridge Widget
- Rate Limits
Developer Dashboard
- SDK and API Keys
- Sandbox vs Live
- Analytics
- User Management
- Test Accounts
- Settings
- Admin
- Webhooks
- Configuring Social Providers
Tutorials
- Farcaster
- Telegram
- Features
- Frameworks
- Integrations
- Webhooks
Migrating to Dynamic
- Migrating to Dynamic
- Migration Tutorials
For Wallets & Chains
Legacy: V1 Embedded Wallets
- V1 Embedded Wallets Overview
- Working with environments that have both v1 and v2 embedded wallets
- Transactional MFA
- Headless
EVM Interactions
Get balance for all wallets
In this example, we will get the balance for each connected wallet.
For each wallet, we will get the provider with useRpcProviders, to fetch the
balance by calling the 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?