eth_getBalance - Base
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
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": ["0x4200000000000000000000000000000000000006", "latest"],
"id": "getblock.io"
}'javascriptimport axios from 'axios';
const data = JSON.stringify({{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": ["0x4200000000000000000000000000000000000006", "latest"],
"id": "getblock.io"
});
const config = {
method: 'post',
url: 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
headers: {
'Content-Type': 'application/json'
},
data: data
};
axios(config)
.then(response => console.log(JSON.stringify(response.data)))
.catch(error => console.log(error));pythonimport requests
import json
url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"
payload = json.dumps({
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": ["0x4200000000000000000000000000000000000006", "latest"],
"id": "getblock.io"
})
headers = {
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers, data=payload)
print(response.text)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": ["0x4200000000000000000000000000000000000006", "latest"],
"id": "getblock.io"
}"#)
.send()
.await?;
println!("{}", response.text().await?);
Ok(())
}Response
json{
"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
- Wallet Balance Display: Show user's ETH balance in wallet interfaces.
- Transaction Validation: Verify sufficient balance before sending transactions.
- Portfolio Tracking: Aggregate balances across multiple addresses.
- Smart Contract Verification: Check contract balances for DeFi applications.
- 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
javascriptconst { ethers } = require('ethers');
const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');
async function getBalance(address) {
const balance = await provider.getBalance(address);
console.log('Balance (wei):', balance.toString());
console.log('Balance (ETH):', ethers.formatEther(balance));
return balance;
}
// Check WETH contract balance on Base
getBalance('0x4200000000000000000000000000000000000006');javascriptimport { createPublicClient, http, formatEther } from 'viem';
import { base } from 'viem/chains';
const client = createPublicClient({
chain: base,
transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});
async function getBalance(address) {
const balance = await client.getBalance({
address: address
});
console.log('Balance (wei):', balance.toString());
console.log('Balance (ETH):', formatEther(balance));
return balance;
}
// Check WETH contract balance on Base
getBalance('0x4200000000000000000000000000000000000006');