eth_getBalance - Base

Example code for the eth_getBalance JSON-RPC method. Complete guide on how to use eth_getBalance JSON-RPC in GetBlock Web3 documentation.

This method returns the ETH balance of a specified address on the Base network. Since Base uses ETH as its native gas token, this method returns the native token balance in wei.

Parameters

Parameter
Type
Required
Description

address

string

Yes

The 20-byte address to check the balance of

blockParameter

string

Yes

Block number in hex, or "latest", "earliest", "pending"

Request

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

Response

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

Response Parameters

Parameter
Type
Description

jsonrpc

string

JSON-RPC protocol version ("2.0")

id

string

Request identifier matching the request

result

string

Hexadecimal balance in wei

Use Cases

  1. Wallet Balance Display: Show user's ETH balance in wallet interfaces.

  2. Transaction Validation: Verify sufficient balance before sending transactions.

  3. Portfolio Tracking: Aggregate balances across multiple addresses.

  4. Smart Contract Verification: Check contract balances for DeFi applications.

  5. Historical Analysis: Query balances at specific block heights.

Error Handling

Error Code
Message
Description

-32602

Invalid params

Invalid address format or block parameter

-32603

Internal error

Node internal failure

-32600

Invalid request

Malformed JSON-RPC request

Web3 Integration

Last updated

Was this helpful?