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.

Pay per request with USDC is available for supported RPC calls and batches without an account where billing requirements allow. For a few reads, check its supported methods and limits before choosing account access. The downloadable scripts below use an RPC key and do not make payments.

Try SolidRPC without an account.

Copy and run this request to check the connection. No account, API key, or payment is needed. Each command makes one read-only request and stops after 15 seconds.

Base · check chain ID
curl --silent --show-error --fail-with-body --max-time 15 \
  'https://rpc.solidrpc.io/public/evm/8453' \
  -H 'Content-Type: application/json' \
  --data '{"jsonrpc":"2.0","id":1,"method":"eth_chainId","params":[]}'

Expected result: 0x2105 (Base, chain ID 8453).

Use public RPC for small checks and light traffic. Public limits apply, including single-call requests, rate limits, and a 2 MiB response cap. Stop on errors or throttling. Indexing and production backfills need an authenticated endpoint.

Need your agent to manage keys, usage, and billing? Set up agent access with an approved budget. Free accounts do not support agent control.

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.

For the downloadable script below, use an ak_ RPC key. Follow agent account setup when you need delegated account access. A management token beginning with sa_ cannot be used for RPC calls.

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.