ethereum / wiki

The Ethereum Wiki
https://www.ethereum.org
14.75k stars 2.57k forks source link

Passing variables into params:[]? #626

Closed tucker-chambers closed 6 years ago

tucker-chambers commented 6 years ago

Hi there, I am trying to build a function (in Julia) on top of some of the functions found in this JSON RPC documentation.

function eth_getBlockByNumber(block_number, boolean_value)
    #block_number: pass as Int
    #boolean_value: true or false (If true, returns full tx objects; if false, only hashes of tx)
    block_number = string(block_number, base=16) #convert to hex for JSON
    block_number = "0x" * block_number

    uri = "http://localhost:8545/"
    header = ["Content-Type"=> "application/json"]
    data = """{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":[$block_number, $boolean_value],"id":1}"""

    r = HTTP.request("POST", uri, header, data)
    result = JSON.parse(String(r.body))
    return result
end

Which when I run with a block number argument, returns this error:

"error"   => Dict{String,Any}("message"=>"invalid character 'x' after array element","code"=>-32600)

And if I run it without the "0x" added, I get the same error, just that the invalid character is the first character in the block_number string, whatever it may be. I've looked at the HEX value encoding section, but am not sure where I am going wrong.

Thanks for any help.

tucker-chambers commented 6 years ago

The fix was to enclose $block_number in parantheses as well. Like so: "$block_number"