# eth_getBalance - Immutable RPC Method

Returns the balance of a given address on Immutable.

> **Why Immutable?** Build on the gaming-optimized zkEVM with 660+ games, 5.5M+ Passport signups, and $40M TVL with first EVM chain with enforceable royalties, Polygon zkEVM technology, $2B+ ecosystem funding, and Agglayer cross-chain liquidity.

## When to Use This Method

`eth_getBalance` is fundamental for AAA game studios, indie game developers, and NFT gaming teams seeking enforceable royalties:

- **Wallet applications**: Display user balances and enable balance-dependent operations on Immutable
- **Transaction validation**: Verify accounts have sufficient funds before submitting transactions to Immutable
- **DeFi monitoring**: Track collateral positions, liquidity pools, and TVL across Web3 gaming (Gods Unchained, RavenQuest), gaming NFTs with enforced royalties, and cross-chain game assets
- **Accounting and reconciliation**: Cross-reference on-chain balances against off-chain ledger entries for financial reporting

## Request Parameters

- `address` (`DATA, required`): 20-byte address to check balance for
- `blockParameter` (`QUANTITY|TAG, required`): Block number in hex, or "latest", "earliest", "pending", "safe", "finalized"

## Request Example

```json
{
  "jsonrpc": "2.0",
  "method": "eth_getBalance",
  "params": [
    "0x3A0C2Ba54D6CBd3121f01b96DFd20e99D1696c9D",
    "latest"
  ],
  "id": 1
}
```

## Response Fields

- `result` (`QUANTITY, required`): Integer of the current balance in wei (hexadecimal)

## Successful Response

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

## Common Use Cases

### 1. Display Formatted Wallet Balance with Ether Conversion

Retrieve and display a human-readable balance for any address on Immutable. Convert the wei result to ether client-side using your web3 library.

```javascript
import { JsonRpcProvider, formatEther } from 'ethers';

const provider = new JsonRpcProvider('https://api-immutable-zkevm-mainnet.n.dwellir.com/YOUR_API_KEY');

async function displayBalance(address) {
  const balanceWei = await provider.getBalance(address);
  const balance = formatEther(balanceWei);
  console.log(`Balance: ${balance} Immutable`);
  return balance;
}

displayBalance('0x3A0C2Ba54D6CBd3121f01b96DFd20e99D1696c9D');
```

### 2. Monitor Whale Wallet Activity with Polling and Threshold Alerts

Poll a high-value wallet on Immutable at regular intervals. Trigger an alert when the balance crosses a defined threshold, useful for tracking DeFi movements or exchange hot wallet activity.

```python
from web3 import Web3
import time

w3 = Web3(Web3.HTTPProvider('https://api-immutable-zkevm-mainnet.n.dwellir.com/YOUR_API_KEY'))
address = '0x3A0C2Ba54D6CBd3121f01b96DFd20e99D1696c9D'
threshold_wei = w3.to_wei(100, 'ether')

def monitor_balance():
    previous_balance = w3.eth.get_balance(address)
    while True:
        time.sleep(15)
        current_balance = w3.eth.get_balance(address)
        if abs(current_balance - previous_balance) > threshold_wei:
            print(f'Balance changed by more than 100 Immutable')
        if current_balance > w3.to_wei(1000, 'ether'):
            print(f'Whale alert: wallet exceeds 1000 Immutable')
        previous_balance = current_balance

monitor_balance()
```

### 3. Historical Balance Tracking Using Block Tags

Query an account's balance at a specific block height to build a historical balance timeline. This is essential for audit trails, tax reporting, and analyzing wallet behavior over time on Immutable.

```go
package main

import (
    "context"
    "fmt"
    "log"
    "math/big"

    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/ethclient"
)

func main() {
    client, _ := ethclient.Dial("https://api-immutable-zkevm-mainnet.n.dwellir.com/YOUR_API_KEY")

    address := common.HexToAddress("0x3A0C2Ba54D6CBd3121f01b96DFd20e99D1696c9D")

    // Query balance at a specific block number
    blockNumber := big.NewInt(1000000)
    historicalBalance, _ := client.BalanceAt(context.Background(), address, blockNumber)
    fmt.Printf("Historical balance at block 1,000,000: %s wei\n", historicalBalance.String())

    // Query latest balance for comparison
    currentBalance, _ := client.BalanceAt(context.Background(), address, nil)
    change := new(big.Int).Sub(currentBalance, historicalBalance)
    fmt.Printf("Balance change: %s wei\n", change.String())
}
```

## Best Practices

- **Cache balances with short TTL**: Set a 2-5 second cache duration for balance queries to reduce RPC calls while keeping data fresh enough for most UI use cases
- **Convert wei to ether client-side**: Use `formatEther` (ethers.js) or `fromWei` (web3.py) rather than relying on node-side conversion, which the JSON-RPC does not provide
- **Use `pending` tag cautiously**: Balances returned with the `pending` block tag may reflect unconfirmed state changes and differ from finalized on-chain values
- **For batch balance queries, use `eth_call` with multicall**: When querying balances for many addresses, bundle them through a multicall contract to reduce individual RPC round-trips

## Code Examples

cURL
JavaScript
Python
Go

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

```javascript
import { JsonRpcProvider, formatEther } from 'ethers';

const provider = new JsonRpcProvider('https://api-immutable-zkevm-mainnet.n.dwellir.com/YOUR_API_KEY');

const address = '0x3A0C2Ba54D6CBd3121f01b96DFd20e99D1696c9D';
const balanceWei = await provider.getBalance(address);
const balance = formatEther(balanceWei);

console.log(`Balance: ${balance}`);

// Get balance at specific block
const historicalBalance = await provider.getBalance(address, 1000000);
console.log(`Historical balance: ${formatEther(historicalBalance)}`);
```

```python
from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://api-immutable-zkevm-mainnet.n.dwellir.com/YOUR_API_KEY'))

address = '0x3A0C2Ba54D6CBd3121f01b96DFd20e99D1696c9D'
balance_wei = w3.eth.get_balance(address)
balance = w3.from_wei(balance_wei, 'ether')

print(f'Balance: {balance}')

# Get balance at specific block
historical_balance = w3.eth.get_balance(address, block_identifier=1000000)
print(f'Historical balance: {w3.from_wei(historical_balance, "ether")}')
```

```go
package main

import (
    "context"
    "fmt"
    "log"
    "math/big"

    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/ethclient"
)

func main() {
    client, err := ethclient.Dial("https://api-immutable-zkevm-mainnet.n.dwellir.com/YOUR_API_KEY")
    if err != nil {
        log.Fatal(err)
    }

    address := common.HexToAddress("0x3A0C2Ba54D6CBd3121f01b96DFd20e99D1696c9D")
    balance, err := client.BalanceAt(context.Background(), address, nil)
    if err != nil {
        log.Fatal(err)
    }

    // Convert to ether
    fbalance := new(big.Float).SetInt(balance)
    ethValue := new(big.Float).Quo(fbalance, big.NewFloat(1e18))

    fmt.Printf("Balance: %f\n", ethValue)
}
```

## Related Methods

- [`eth_getCode`](https://www.dwellir.com/docs/immutable/eth_getCode) - Get contract bytecode
- [`eth_getTransactionCount`](https://www.dwellir.com/docs/immutable/eth_getTransactionCount) - Get account nonce
