3

I began by trying to follow the article on front running bancor with Python. I thought it would be easy to send an api request to my full node then replicate the same request in Python--all following the tutorial. The only difference was that the author used Geth and I am running Parity. The inability to figure out how to use JSON RPC has led me down a rabbit hole. I don't really know (1) what I'm doing wrong or (2) if I even conceptually understand JSON RPC at this point.

The problem:

I should be able to run this curl command: curl -X POST --data \ '{"jsonrpc":"2.0","method":"eth_getTransactionByHash", \ "params":["0x314e0246cfc55bc0882cbf165145c168834e99924e3ff7619ebd8290e713386d"], \ "id":123}' localhost:8545

And get a result like this:

{"jsonrpc":"2.0","id":123, "result":{ "blockHash":"0x42ea1578c23b159186853961dfbdfcdec6b40d23d8f1d971827412bc6948386b", "blockNumber":"0x3dfb88", "From":"0xcaf82fcb3a0323566c0f306684376e3e66d6284b", "To":"0x77a77eca75445841875ebb67a33d0a97dc34d924", "gasPrice":"0xba43b7400", "hash":"0x314e0246cfc55bc0882cbf165145c168834e99924e3ff7619ebd8290e713386d", "value":"0x6c6b935b8bbd400000", ...}}

Howevever when I run it with localnode connected to parity I only get:

Supplied content type is not allowed. Content-Type: application/json is required

I found the Parity JSON-RPC API documentation and realized the formatting is different.
enter image description here

So I reformatted the curl command to look like this:

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

I solved the Content Type error but then got a null result:

{"jsonrpc":"2.0","result":null,"id":1}

Then looking at this stack exchange article I realized that Parity has it's own Web3 console. So, I thought maybe I don't have to use curl at all, and can just run.

web3.eth.getTransaction('0x314e0246cfc55bc0882cbf165145c168834e99924e3ff7619ebd8290e713386d')

enter image description here

and I still get null return.

As a side note I have also tried to do the call using Infura's api

curl --include \
 --header "Content-Type: application/json" \
 --header "Accept: application/json" \

'https://api.infura.io/v1/jsonrpc/mainet/getTransaction?params=0x314e0246cfc55bc0882cbf165145c168834e99924e3ff7619ebd8290e713386d'

Infura But am getting 404 return.

I really want to understand what I am doing wrong but I don't know where exactly to find the resources to teach myself, and feel a little stuck. Thanks in advance for anything that can point me in the right direction.

2
  • Are you running this on Windows? I'v tried with infura.io and this works curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":["0x314e0246cfc55bc0882cbf165145c168834e99924e3ff7619ebd8290e713386d"],"id":123}' https://mainnet.infura.io/<token>
    – Ismael
    Oct 26, 2017 at 18:19
  • No, Ubuntu 16.04.
    – Amazing
    Oct 26, 2017 at 20:15

2 Answers 2

1

Call it like this

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

It need

-H "Content-Type: application/json"
0

The call you provided seems proper, and it works on my local parity - you might've had blockchain not completely synced up.

3
  • Would you be willing to show me exactly how you entered it? My node is definitely fully synced
    – Amazing
    Dec 18, 2017 at 1:23
  • I literally copied your call, and ran it from terminal on an Ubuntu server running parity: :~$ curl --data '{"jsonrpc":"2.0","method":"eth_getTransactionByHash", "params":["0x314e0246cfc55bc0882cbf165145c168834e99924e3ff7619ebd8290e713386d"], "id":1, "jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545 {"jsonrpc":"2.0","result":{"blockHash":"0x42ea1578c23b159186853961dfbdfcdec6b40d23d8f1d971827412bc6948386b","blockNumber":"0x3dfb88","chainId":"0x1"...
    – kolinko
    Feb 5, 2018 at 23:56
  • (also, why the downvotes? :O )
    – kolinko
    Feb 5, 2018 at 23:57

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.