The Basics
- Add Login / Signup
- Chains / Networks
- Wallets
- 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
Get balance
Here’s an example of using the getBalance
method to get the balance of the connected user’s wallet
import { useEffect, useState } from 'react';
import {
useDynamicContext,
DynamicContextProvider,
UserProfile,
useIsLoggedIn,
} from '@dynamic-labs/sdk-react-core';
const Home = () => {
const { user, handleLogOut, setShowAuthFlow, primaryWallet } =
useDynamicContext();
const isLoggedIn = useIsLoggedIn();
const [balance, setBalance] = useState<string | null>(null);
useEffect(() => {
primaryWallet?.getBalance().then((balance) => {
if (balance) {
setBalance(balance.toString());
}
});
}, [primaryWallet]);
if (isLoggedIn) {
return (
<div>
<p>User is logged in</p>
{ primaryWallet && <>}
<p>Address: {primaryWallet.address}</p>
<p>Balance: {balance}</p>
</>}
<button type='button' onClick={handleLogOut}>
Log Out
</button>
</div>
);
}
return (
<div>
<button type='button' onClick={() => setShowAuthFlow(true)}>
Connect With My Wallet
</button>
</div>
);
};
const App = () => (
<DynamicContextProvider
settings={{
appLogoUrl:
'https://upload.wikimedia.org/wikipedia/commons/3/34/Examplelogo.svg',
appName: 'Example App',
environmentId: 'REPLACE_WITH_YOUR_ENV_ID',
onAuthSuccess: ({
user,
}: {
user: UserProfile;
}) => {
console.log(
`Welcome ${user.email}`,
);
window.location.assign('/success');
},
}}
>
<Home />
</DynamicContextProvider>
);
export default App;
Was this page helpful?