1

I'm trying to get the ether balance for any ethereum address. I've set up a node with the Ethereum daemon, but as far as I can tell, using eth_getBalance you can only get the balance of your own Accounts, and you can't query against an arbitrary address in the blockchain.

Is there a way to do this using the JSON RPC API? If not, how do block explorers provide this information?

Thank you!

1
  • 2
    "...as far as i can tell, using eth_getBalance you can only get the balance of your own Accounts, and you can't query against an arbitrary address in the blockchain." This is not true. You can pass any address you like.
    – user19510
    Jan 10, 2018 at 17:32

2 Answers 2

0

If you’re querying for historical balances, you have to be running an archive node otherwise all the balances will report as zero.

If you’re not running an archive note, you can query any address as far back as 250 blocks (or some small number) from the head.

1
  • 1
    no, he is querying the` 'latest'` block state, so he doesn't need to run historical node
    – Nulik
    Jul 6, 2018 at 19:12
0

You can use eth_getBalance for any account. In the example below just replace the account address from the params with your address and it should return the balance but if your geth client is different from the localhost:8545 replace it with your host IP and port.

curl -X POST localhost:8545 \
-H "Content-Type: application/json" \
--data \
'
{
  "jsonrpc": "2.0",
  "method": "eth_getBalance",
  "params": ["0x0ADfCCa4B2a1132F82488546AcA086D7E24EA324", "latest"],
  "id": 1
}
'                 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.