For the complete documentation index, see llms.txt. This page is also available as Markdown.

eth_getBalance - Optimism

Example code for the eth_getBalance json-rpc method. Сomplete guide on how to use eth_getBalance json-rpc in GetBlock.io Web3 documentation.

This method retrieves the native ETH balance of any address on the Optimism network. The balance is returned in wei (the smallest unit of ETH, where 1 ETH = 10^18 wei). You can query the balance at a specific block height or use tags like 'latest', 'earliest', or 'pending'. This is essential for wallet applications, balance verification, and transaction validation.

Parameters

Parameter
Type
Description
Required

address

DATA, 20 Bytes

The address to check the balance of.

Yes

block

QUANTITY|TAG

Block number in hex, or 'latest', 'earliest', 'pending'.

Yes

Request Sample

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_getBalance",
    "params": ["0xb8b2522480f850eb198ada5c3f31ac528538d2f5", "latest"],
    "id": "getblock.io"
}'

Response

A successful response returns the following:

 {
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0x0"
}

Response Parameters

  • id: A unique request identifier, matching the id sent in the request body.

  • jsonrpc: Specifies the use of JSON-RPC version 2.0.

  • result: The balance in wei as a hexadecimal string. 0x1bc16d674ec80000 equals 2 ETH (2000000000000000000 wei).

Use Case

The eth_getBalance method is commonly used for:

  • Wallet balance display

  • Transaction validation

  • Account monitoring

  • Portfolio tracking

Error handling

Status Code
Error Message
Cause

404

Not found

Missing or invalid ACCESS_TOKEN.

-32602

Invalid argument

Wallet address isn't accurate or incomplete

Integration with Web3

The eth_getBalance can help developers:

  • Fetch balances dynamically without requiring a transaction

  • Power trustless dashboards and explorers

  • Validate user accounts before executing transactions

  • Track portfolio values in real time

  • Access historical balances using specific block numbers

Last updated

Was this helpful?