⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip the expensive compute units.
Switch Today →
Skip to main content

eth_getBalance

Returns the ETH balance of a given address on Optimism Layer 2.

When to Use This Method

eth_getBalance is essential for:

  • Wallet Applications - Display user balances on Optimism
  • Transaction Validation - Check if account has sufficient funds for L2 operations
  • DeFi Applications - Monitor collateral and liquidity on Optimism
  • Account Monitoring - Track balance changes over time

Parameters

  1. Address - DATA, 20 bytes

    • The address to check balance for
    • Format: 0x prefixed, 40 hex characters
  2. Block Parameter - QUANTITY|TAG

    • "latest" - Most recent block (default)
    • "earliest" - Genesis block
    • "pending" - Pending state
    • "safe" - Latest safe block
    • "finalized" - Latest finalized block
    • Block number in hex format
{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": [
"0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"latest"
],
"id": 1
}

Returns

QUANTITY - Integer of the current balance in wei.

  • Type: Hexadecimal string
  • Unit: Wei (1 ETH = 10^18 wei)
  • Format: 0x prefixed

Implementation Examples

curl -X POST https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": [
"0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"latest"
],
"id": 1
}'

Response Example

Successful Response

{
"jsonrpc": "2.0",
"id": 1,
"result": "0x1a055690d9db80000"
}

This represents 0x1a055690d9db80000 wei = 1.85 ETH on Optimism L2.

Error Response

{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32602,
"message": "Invalid params: invalid address"
}
}

Optimism L2 Considerations

Gas Cost Advantages

On Optimism, balance checks are significantly cheaper than Ethereum mainnet:

async function compareGasCosts() {
// Optimism balance check
const optimismGas = await provider.estimateGas({
to: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
data: "0x" // Simple balance check call
});

console.log('Optimism gas cost: ~1/10th of Ethereum mainnet');
console.log('Perfect for frequent balance monitoring');
}

L2-Specific Balance Monitoring

class OptimismBalanceMonitor {
constructor(provider, address) {
this.provider = provider;
this.address = address;
this.lastBalance = null;
}

async start(callback, interval = 1000) { // Faster polling on L2
setInterval(async () => {
const currentBalance = await this.provider.getBalance(this.address);

if (this.lastBalance && currentBalance !== this.lastBalance) {
const change = currentBalance - this.lastBalance;
callback({
address: this.address,
network: 'Optimism',
chainId: 10,
previousBalance: this.lastBalance,
currentBalance,
change,
changeFormatted: formatEther(change)
});
}

this.lastBalance = currentBalance;
}, interval);
}
}

Common Use Cases on Optimism

1. DeFi Balance Tracking

async function trackDeFiBalances(userAddress) {
const provider = new JsonRpcProvider('https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY');

// Get ETH balance
const ethBalance = await provider.getBalance(userAddress);

// Get gas price for transaction cost estimation
const feeData = await provider.getFeeData();

return {
address: userAddress,
network: 'Optimism',
ethBalance: formatEther(ethBalance),
estimatedTxCost: formatEther(feeData.gasPrice * 21000n),
canAffordBasicTx: ethBalance > feeData.gasPrice * 21000n
};
}

2. L2 Bridge Balance Verification

async function verifyBridgeBalance(l2Address) {
const balance = await provider.getBalance(l2Address);
const blockNumber = await provider.getBlockNumber();

return {
address: l2Address,
balance: formatEther(balance),
blockNumber,
timestamp: Date.now(),
network: 'Optimism L2',
verified: true
};
}

Need help? Contact our support team or check the Optimism documentation.