I have Geth running locally, and for whatever reason the JSON-RPC api is not working. Web3.js is working fine.
I've tried to start the console several ways:
geth --rpc --rpcapi "eth,net,admin,web3" --verbosity 0 --unlock 0 console
I've also included the port and other combinations, such as starting RPC from within the console using admin.startRPC(addr,host)
.
Each time I make an RPC call, for example:
curl -X POST --data '{"jsonrpc":"2.0","method":"net_version","params":[],"id":67}'
I get a variation of the following output:
(anonymous): Line 1:9 Unexpected identifier (and 1 more errors)
I've also tried RPC calls omitting -X POST
or specifying rpcaddr:rpchost
at the end.
I don't have any other connections, or other geth-attached windows.
Best Answer
To make an RPC call and get response, you need to initialize the target node with an --rpcaddr (IP Address) and an --rpcport. The default rpc port for geth is
8545
. You can also start this process from the interactive JavaScript console usingadmin.startRPC(addr, port)
.And while making an RPC call:
Replace the rpcaddr with your IP address and rpcport with
8545
if you haven't modified it.I have simulated the same commands and I got the result. Geth node is running on one terminal and I made an RPC call from another terminal. Check out this screenshot: