Skip to main content
← All agent examples

Read ETH and USDC balances on Base.

Build a bounded Base balance monitor with eth_getBalance and ERC-20 balanceOf, exact integer formatting, and a saved RPC key. This recipe reads blockchain data. It does not create an account, sign a transaction, or fund credit.

Give your agent the task.

Task prompt
Read the ETH and native USDC balances of my public wallet address on Base. Start with one sample. Use SolidRPC, check network support, and ask before creating paid access or spending money. Keep keys private and report the block used for the balances.

New to SolidRPC? Follow agent account setup first. A small task may fit public RPC. Account delegation requires paid access, and this script expects a separate ak_ RPC key.

Check coverage and limits.

Required methods: eth_chainId, eth_blockNumber, eth_getBalance, eth_call. Read the network catalog and rate limits before a large run. One billable method call uses one response unit. Retries and range splits add requests.

Base mainnet has chain ID 8453. Native USDC is 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913. Both balances are queried at the same block number. ETH has 18 decimal places and USDC has 6. Integer formatting avoids floating-point rounding. A reorganization can still change the meaning of a recent block number.

Contract reference: Circle’s official USDC addresses. Do not substitute a similarly named bridged token.

Run the example.

Download base-balances.mjs and its shared rpc-client.mjs into the same folder. Review them before running. The helper refuses management tokens and redirects, sends the RPC key in a header, and makes read-only calls with bounded retries.

Configuration
# Node.js 22 or newer. Save both linked scripts in one folder.
export RPC_ORIGIN='https://rpc.solidrpc.io'
export RPC_KEY_FILE='/absolute/path/to/private/rpc-key'
Run
export WALLET_ADDRESS='0xYOUR_PUBLIC_WALLET_ADDRESS'
SAMPLES=1 node base-balances.mjs
# For a bounded monitor: SAMPLES=10 INTERVAL_SECONDS=15

Keep the key file outside your repository. The scripts print results without credentials. They do not automatically purchase more credit when the account runs out.

Know what success looks like.

Each output line contains chain ID, block number, public wallet address, ETH balance, and USDC balance. One sample uses four calls including the chain check. Additional samples use three calls each, before retries. A zero balance is a valid result.

Output shape
{"chainId":8453,"block":"...","address":"0x...","eth":"0.000000000000000000","usdc":"0.000000"}

For errors, inspect HTTP status and the JSON-RPC error separately. Use the error reference. Report any partial result instead of claiming the entire task completed.

Need account access? Read the setup guide or open the management API contract.