INFURA / infura

Official Public Repository for INFURA
https://infura.io
381 stars 62 forks source link

eth_getBalance using a block number throws unmarshal error #205

Closed donpdonp closed 3 years ago

donpdonp commented 3 years ago

Posting eth_getBalance to infura works as expected.

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

https://infura.io/docs/ethereum/json-rpc/eth-getBalance The docs say the second parameter is 'an integer block number, or the string "latest"'

When I specify a block

{"jsonrpc":"2.0","method":"eth_getBalance",
"params": ["0xc94770007dda54cF92009BFF0dE90c06F603a09f", 3016743],"id":1}

This error is thrown

{"jsonrpc":"2.0","id":1,"error":{"code":-32602,
"message":"invalid argument 1: json: cannot unmarshal number into Go value of type string"
}}

I also tried the blocknumber as a string "3016743" just to see what would happen, and that throws invalid argument 1: hex string without 0x prefix.

whats going on here?

averyonghub commented 3 years ago

You're right, the docs aren't totally clear. What this should say is an int block number as a hex string, in accordance with the official spec: https://eth.wiki/json-rpc/API#the-default-block-parameter. Try this for your payload:

{"jsonrpc":"2.0","method":"eth_getBalance",
"params": ["0xc94770007dda54cF92009BFF0dE90c06F603a09f", "0x2E0827"],"id":1}

(Note: you'll need archive access for a block that far back!)

donpdonp commented 3 years ago

wow yeah the docs should be amended to say what the second parameter really is. looks like this answers #194 as well. thanks!