7

I am trying to do a simple curl from the cmd line to my private blockchain. I have the geth console running on localhost:8545

The curl command I am executing is the following

curl -X POST --data '{"jsonrpc":"2.0","method":"net_version","params":[],"id":67}' http://localhost:8545

I also have tried many other examples from https://github.com/ethereum/wiki/wiki/JSON-RPC

none of them work on my set up as all the responses are

{"jsonrpc":"2.0","error":{"code":-32600,"message":"invalid character '\\'' looking for beginning of value"}}}

I start geth using this:

geth --rpc --rpcapi "eth,net,web3,personal" --datadir c:\privatechain

3 Answers 3

8

windows needs the content in double quotes and those inside with \"

curl -H "Content-Type: application/json" --data "{\"jsonrpc\":\"2.0\",\"method\":\"net_version\",\"params\":[],\"id\":67}" http://localhost:8545
1

you should add address,as follows: curl -X POST --data '{"jsonrpc":"2.0","method":"net_version","params":[],"id":67}' localhost:8545

11
  • Thank you. I did have that already.. I forgot to state that in my OP... Even with that I still get the error unfortunately Aug 2, 2017 at 7:15
  • At first, you must be start testrc service on single terminal, and then execute JSON RPC op. If you have get error, please tell me error log. Aug 2, 2017 at 7:20
  • the other way, start geth on single terminal: geth --rpc --rpcaddr localhost --rpcport 8545 , and then execute JSON RPC op. Aug 2, 2017 at 7:38
  • I edit the original post to include the localhost:8545 to the command. Using Parity I had to add -H "Content-Type: application/json", but it totally worked. I've seen this once or twice because the quotes were 'enhanced' quotes from autocorrect in my text editor. Type the command in full from command line as opposed to copy and paste (if you're copying and pasting). Aug 2, 2017 at 11:12
  • Unfortunately I am still getting the same error after typing it manually. Its driving me nuts.... Here is a screen shot ibb.co/b5mBEk Aug 2, 2017 at 17:51
0

i try this and it work

curl -X POST -H "Content-Type: application/json" --data '{\"jsonrpc\":\"2.0\",\"method\":\"net_version\",\"params\":[],\"id\":67}' localhost:8545

i'm using terminal powershell in windows

Your Answer

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

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