The eth_getBalance
method returns the balance of a specified Ethereum address in wei. This essential method forms the foundation of wallet applications, financial dashboards, and any DApp that needs to display or work with user account balances.
This method queries the balance of any Ethereum address at a specified block, allowing for both current and historical balance checks.
The address to check for balance
Block number or block tag
Account balance in wei (hexadecimal)
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x1B1AE4D6E2EF500000" // 500 ETH in wei
}
The balance is returned in wei (the smallest unit of ether) as a hexadecimal string. To convert to ether:
parseInt("0x1B1AE4D6E2EF500000", 16)
= 500000000000000000000500000000000000000000 / 1e18
= 500 ETHFor user interfaces, always display balances in a readable format (ETH) rather than the raw wei value.
The blockNumber
parameter accepts these special tags:
latest
: The most recently mined block (current balance)earliest
: The genesis block (initial state)pending
: The pending state/transactionssafe
: The latest "safe" head block (Ethereum only)finalized
: The latest "finalized" block (Ethereum only)// Example of checking multiple account balances
const addresses = [
'0xF977814e90dA44bFA03b6295A0616a897441aceC', // Binance Hot Wallet
'0x42cC527cD31Eb1479ae27Cb4A5eec6a023Cd2E', // Example address
];
for (const address of addresses) {
const balance = await provider.send('eth_getBalance', [address, 'latest']);
console.log(`Balance of ${address}: ${parseInt(balance, 16) / 1e18} ETH`);
}