0

I am writing runtime rpc with multiple parameters:

#[rpc]
pub trait ShivarthuApi<BlockHash> {
    #[rpc(name = "shivarthu_challengerevidence")]
    fn get_challengers_evidence(
        &self,
        at: Option<BlockHash>,
        profile_citizenid: u128,
        offset: u64,
        limit: u16,
    ) -> Result<Vec<Vec<u8>>>;
}

It successfully compiled, but gives invalid params error when called through curl

curl http://localhost:9933 -H "Content-Type:application/json;charset=utf-8" -d   '{
     "jsonrpc":"2.0",
      "id":1,
      "method":"shivarthu_challengerevidence",
      "params": [0, 3, 5]
    }'
{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params: invalid type: number, expected a (both 0x-prefixed or not) hex string with length of 64."},"id":1}

rpc call with named parameters

curl http://localhost:9933 -H "Content-Type:application/json;charset=utf-8" -d   '{
     "jsonrpc":"2.0",
      "id":1,
      "method":"shivarthu_challengerevidence",
      "params": {"profile_citizenid" :0, "offset": 2, "limit":5}
    }'
{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params: invalid type: map, expected a tuple of size 4."},"id":1}
1
  • It works with "params": [null,0, 3, 5] May 6, 2022 at 13:13

1 Answer 1

1

As per the error message above,

Invalid params: invalid type: number, expected a (both 0x-prefixed or not) hex string with length of 64.

This is for the BlockHash parameter, you need to pass an actual hash, i.e. 0x123...def would be applicable. Or null if the Option is empty, any non-null value needs to be a valid BlockHash.

(Generally you most-probably would like to move the Option parameters to the end, or at least that is the pattern followed in Substrate)

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.