Hi I’m new user making my first call, I just copied and pasted an example block of code from https://infura.io/docs/ethereum/json-rpc/eth_getBalance to my cmd window on Windows 10, but substituting my application id into the appropriate place.
I also tested the json against jsonlint and it checked out.
But I keep getting back {“jsonrpc”:“2.0”,“error”:{“code”:-32600,“message”:“invalid json request”}.
This isn’t very helpful because it won’t tell me what’s gone wrong, and jsonlint says everything is fine. Here is the exact code except I took out my app id:
curl -g https://mainnet.infura.io/v3/my-app-id -X POST -H “Content-Type: application/json” -d ‘{“jsonrpc”:“2.0”,“method”:“eth_getBalance”,“params”: [“0x7f2331e9c501eb0cbcd20c7f340d9c8864b93e5e75591b3e7824053079d3a426”,“latest”],“id”:1}’
So there are a couple of things wrong with that sample curl you put in. I’m not sure if its the rich text editor in this site or your own code but the quotes should be ascii quotes not utf-8 left and right quotes. That might trip up curl. Additionally the address you are trying to look up the balance for is invalid. When I try that address the response I get back is
{"jsonrpc":"2.0","id":1,"error":{"code":-32602,"message":"invalid argument 0: hex string has length 64, want 40 for common.Address"}}%
Please make sure the address you are trying to check the balance for is a valid Ethereum address hex string
Thanks for the quick response egalano. I was able to get the request to work using postman app with same exact json format (but using a valid eth address as you mentioned) so I know that the parameters and data are correct and am glad I was able to communicate with the infura api. I’ll work out what’s wrong with how it’s being sent from my side.
P.S. for the benefit of the community I will post another piece of this that had to be in place for my .NET HTTP Client to communicate with infura’s API.
I had to add the following before making the POST.
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
Otherwise there was a " An existing connection was forcibly closed by the remote host" error.
1 Like