eth_getBalance
Returns the balance of a given address on Moonriver.
Why Moonriver? Build on the Moonbeam canary network on Kusama for real-world testing of EVM dApps with Moonbeam code ships here first, full EVM compatibility on Kusama, 80% fee burn mechanism, and XCM cross-chain messaging.
Use Cases#
The eth_getBalance method is essential for:
- Wallet applications - Display user balances
- Transaction validation - Check if account has sufficient funds
- DeFi applications - Monitor collateral and liquidity for production-grade dApp testing, early feature deployment, and Kusama-based EVM applications
- Account monitoring - Track balance changes over time
Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
address | DATA | Yes | 20-byte address to check balance for |
blockParameter | QUANTITY|TAG | Yes | Block number in hex, or "latest", "earliest", "pending", "safe", "finalized" |
Request#
{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": [
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"latest"
],
"id": 1
}
Returns#
| Type | Description |
|---|---|
QUANTITY | Integer of the current balance in wei (hexadecimal) |
Note: 1 native token = 10^18 wei. Convert using balance / 10^18.
Response#
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x1a055690d9db80000"
}
Code Examples#
- cURL
- JavaScript
- Python
- Go
curl -X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": [
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"latest"
],
"id": 1
}'
import { JsonRpcProvider, formatEther } from 'ethers';
const provider = new JsonRpcProvider('');
const address = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
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)}`);
from web3 import Web3
w3 = Web3(Web3.HTTPProvider(''))
address = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'
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")}')
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("")
if err != nil {
log.Fatal(err)
}
address := common.HexToAddress("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY")
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)
}
Error Handling#
| Error Code | Message | Description |
|---|---|---|
| -32602 | Invalid params | Invalid address format or block parameter |
| -32000 | Execution error | Node execution error |
Related Methods#
eth_getCode- Get contract bytecodeeth_getTransactionCount- Get account nonce