9

My contract has a function defined like this:

{"constant":true,"inputs":[],"name":"queryNumEscrows","outputs":
[{"name":"","type":"uint256"}],"payable":false,"type":"function"}

Having no inputs. Its Solidity source code is pretty simple:

function queryNumEscrows() constant returns (uint) {
    return numEscrows;
}

how do I call it from JSON RPC? I've tried this:

endpoint = "queryNumEscrows()" 
web3_sha3(endpoint) = 0x0127efc52bcbe2b7f6d6a1ee29a7acd32c5f2e824b791cd7c97b9c57981bc5ac
no arguments...
data = 0x0127efc5

and when performing the query:

eth_call([{"from": "0xf28dafbfeb41bf32869c9d498da0d651d0206ed4", "to":
"0x27c042342c9ba937214117e11a4970a6145034cb", "data": "0x0127efc5"}])

this is the error it throws:

-32602: invalid or missing value for params[1]

So, I guess probably is something wrong when encoding void parameters into data. How should I do that?

By the way, I used this great explanation: How to call a contract method using the eth_call JSON-RPC API as a reference.

1 Answer 1

4

Summary

Adding the block number to the eth_call JSON-RPC call parameters as suggested by the closed bug eth_call requires block as last parameter #2472 will work.



Details

I created a contract using Browser Solidity as shown in the screen shot below: enter image description here

And here is my result:

Iota:ESE bok$ curl localhost:8545 -X POST --header 'Content-type: application/json' --data '{"jsonrpc":"2.0", "method":"eth_call", "params":[{"to": "0xb82020341122e7c8c4ba6551fd25950681af3570", "data": "0x0127efc5"}, "latest"], "id":1}'
{"jsonrpc":"2.0","id":1,"result":"0x000000000000000000000000000000000000000000000000000000000000007b"}

Reference The default block parameter and eth_call.

eth_call without the block parameter worked previously. I've updated my old ESE Q&As on eth_call usage to add a note about this new requirement.

1

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.