This guide shows you how to read balances and other data through the connected wallet’s provider. useAccount().balance isn’t a live balance; read it from the provider as shown here.
Read an EVM Balance#
useAccount().currentProvider is the wallet’s provider for the active chain family. On EVM chains, call its request() method with an EIP-1193 request:
"use client"
import { useAccount } from "@dogeos/dogeos-sdk"
export function ReadEvmBalanceButton() {
const { address, chainType, currentProvider } = useAccount()
async function onReadBalance() {
if (!address || !currentProvider || chainType !== "evm") return
const balanceHex = await currentProvider.request({
method: "eth_getBalance",
params: [address, "latest"],
})
console.log(BigInt(balanceHex))
}
return (
<button disabled={!address || !currentProvider || chainType !== "evm"} onClick={onReadBalance}>
Read EVM balance
</button>
)
}eth_getBalance returns a hexadecimal quantity in the chain’s smallest unit. On Chikyū, divide by 10^18 to display DOGE, using a bigint-aware formatter to preserve precision. Query again after the account or chain changes.
Other common EVM reads use the same request() method:
| Method | Parameters | Result |
|---|---|---|
eth_getTransactionCount | [address, "pending"] | Transaction count as a hexadecimal quantity |
eth_estimateGas | [{ from: address, to: recipient, value: "0x0" }] | Estimated gas units as a hexadecimal quantity |
eth_blockNumber | [] | Latest block number as a hexadecimal quantity |
These reads do not sign or broadcast a transaction. Handle request failures in your app and offer a retry.
Read a Dogecoin Balance#
For a Dogecoin embedded wallet, call getBalance() on the provider:
"use client"
import { useAccount } from "@dogeos/dogeos-sdk"
export function ReadDogecoinBalanceButton() {
const { address, chainType, currentProvider } = useAccount()
const canReadBalance =
Boolean(address) &&
chainType === "dogecoin" &&
currentProvider != null &&
typeof currentProvider.getBalance === "function"
async function onReadBalance() {
if (!canReadBalance || !currentProvider) return
const balance = await currentProvider.getBalance()
console.log(balance)
}
return (
<button disabled={!canReadBalance} onClick={onReadBalance}>
Read Dogecoin balance
</button>
)
}The result contains confirmed, unconfirmed, and total amounts in Dogecoin’s smallest unit (10^8 units per DOGE). Use the provider for the active Dogecoin connection. External wallets can expose different method names; check the wallet’s API when adding one to your app.
Read the Solana Account#
For Solana wallets, currentProvider is the wallet’s own Solana provider. Browser-extension wallets usually expose publicKey; WalletConnect wallets answer solana_getAccounts:
"use client"
import { useAccount } from "@dogeos/dogeos-sdk"
export function SolanaAccount() {
const { chainType, currentProvider } = useAccount()
async function onReadAccount() {
if (!currentProvider || chainType !== "solana") return
if ("publicKey" in currentProvider && currentProvider.publicKey) {
console.log(String(currentProvider.publicKey))
return
}
if ("request" in currentProvider && typeof currentProvider.request === "function") {
const accounts = await currentProvider.request({ method: "solana_getAccounts" })
console.log(accounts)
}
}
return <button onClick={onReadAccount}>Read Solana account</button>
}Check Which Chain Families the Wallet Supports#
useConnectors() returns the connected wallet’s providers, one per chain family it supports:
"use client"
import { useConnectors } from "@dogeos/dogeos-sdk"
export function ProviderFamilies() {
const { connectors, currentProvider } = useConnectors()
if (!connectors) {
return <p>No wallet connected.</p>
}
return (
<ul>
<li>EVM: {connectors.evm ? "available" : "unavailable"}</li>
<li>Dogecoin: {connectors.dogecoin ? "available" : "unavailable"}</li>
<li>Current provider: {currentProvider ? "ready" : "missing"}</li>
</ul>
)
}