eth_getBalance - Ethereum
Check the balance of a specified Ethereum address with the balance method. Query account balance at specific blocks or transaction states, supporting various time points like latest or pending
The eth_getBalance method is part of the Ethereum JSON-RPC API and is used to retrieve the balance of a specified Ethereum address.
This method allows you to check the account balance at a specific block or transaction state, making it useful for various DApps and Ethereum-based applications. The method can be queried with the latest, earliest, or pending block tags to get the balance at different points in time. It provides a convenient API method to access the account balance, supporting both request and parameters such as the account address and block tag.
Supported Networks
The eth_getBalance RPC Ethereum method works on the following Ethereum network types
Mainnet
Testnet: Sepolia, Holesky
Parameters
DATA: A 20-byte Ethereum account address to retrieve the balance for. The address must be in hexadecimal format, prefixed with 0x. QUANTITY|TAG: A string representing the block number or one of the following tags:
latest (default): Retrieves the balance of the account at the latest block.
earliest: Retrieves the balance at the first block (genesis block).
pending: Retrieves the balance of the account in the pending block.
Request
URL
To make a request to the eth_getBalance method, you can use the following curl command. The request sends a JSON-RPC query to the Ethereum network via the GetBlock API
Response
The response will contain the balance of the specified Ethereum address, represented as a hexadecimal string in Wei. Below is an example response
Response Description
result: The balance of the Ethereum address in Wei, given as a hexadecimal string. In the example, the balance is 0x36ea, which is the equivalent of 14006 Wei.
Use Case
The eth_getBalance method is often used in decentralized applications (DApps), including those integrated with MetaMask, to check the balance of Ethereum accounts before performing transactions. For example, DApps may need to verify that a user has sufficient funds to complete a transaction or make a purchase. By using the eth_getBalance method, developers can easily retrieve the balance of an account at any given block or the latest state of the Ethereum blockchain. When interacting with MetaMask, this method can be called to display the user's wallet balance in real-time, providing a seamless experience for users during transactions.
Code Example
To retrieve the balance of an address using axios, you can use the eth_getBalance method as follows
This code will retrieve the balance of the specified address on the Ethereum mainnet and print it in ETH.
Common Errors
eth_getBalance error: Common issues when using the eth_getBalance method include incorrect address format, network connectivity problems, or invalid block/tag parameters. Ensure that the address is valid, and the network you are querying is correct.
Last updated