eth_getBalance - Polygon

The eth_getBalance method returns the balance of the account at the given address. The balance is returned in wei, which is the smallest unit of MATIC (1 MATIC = 10^18 wei).

Parameters

ParameterTypeRequiredDescription
addressstringYesThe 20-byte account address to check balance
blockParameterstringYesBlock number in hex, or "latest", "earliest", "pending", "safe", "finalized"

Request

cURL

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

JavaScript (Axios)

javascriptimport axios from 'axios';

const url = 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/';

const payload = {
    jsonrpc: '2.0',
    method: 'eth_getBalance',
    params: ["0x742d35Cc6634C0532925a3b844Bc9e7595f5bEb1", "latest"],
    id: 'getblock.io'
};

axios.post(url, payload, {
    headers: { 'Content-Type': 'application/json' }
})
.then(response => console.log(response.data))
.catch(error => console.error(error));

Python (requests)

pythonimport requests

url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"

payload = {
    "jsonrpc": "2.0",
    "method": "eth_getBalance",
    "params": ["0x742d35Cc6634C0532925a3b844Bc9e7595f5bEb1", "latest"],
    "id": "getblock.io"
}

response = requests.post(url, headers={"Content-Type": "application/json"}, json=payload)
print(response.json())

Rust (reqwest)

rustuse reqwest::header;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    
    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header(header::CONTENT_TYPE, "application/json")
        .body(r#"{
            "jsonrpc": "2.0",
            "method": "eth_getBalance",
            "params": ["0x742d35Cc6634C0532925a3b844Bc9e7595f5bEb1", "latest"],
            "id": "getblock.io"
        }"#)
        .send()
        .await?;
    
    println!("{}", response.text().await?);
    Ok(())
}

Response

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

Response Parameters

FieldTypeDescription
jsonrpcstringJSON-RPC version (2.0)
idstringRequest identifier
resultvariesThe balance in wei as a hexadecimal string

Use Case

The eth_getBalance method is useful for:

  • Check wallet balances
  • Verify sufficient funds before transactions
  • Track account value changes
  • Build portfolio trackers

Error Handling

Status Code / ErrorCause
403Forbidden — Missing or invalid ACCESS-TOKEN
-32600Invalid Request — Malformed request body
-32602Invalid params — Invalid method parameters

Web3 Integration

Ethers.js

javascriptimport { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

const result = await provider.send('eth_getBalance', ["0x742d35Cc6634C0532925a3b844Bc9e7595f5bEb1", "latest"]);
console.log('Result:', result);

Viem

javascriptimport { createPublicClient, http } from 'viem';
import { polygon } from 'viem/chains';

const client = createPublicClient({
    chain: polygon,
    transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});

const result = await client.request({
    method: 'eth_getBalance',
    params: ["0x742d35Cc6634C0532925a3b844Bc9e7595f5bEb1", "latest"]
});
console.log('Result:', result);