I'm trying to call my node's chain_getBlock
RPC method. I expect to provide a block hash, and get back a complete block.
For starters, I've confirmed that the call I plan to make works as expected when just using curl
directly.
# This call works
$ curl http://127.0.0.1:9933 -H "Content-Type:application/json;charset=utf-8" -d '{"jsonrpc":"2.0", "id":1, "method":"chain_getBlock", "params": ["505914d65fcf1049e630441127ca8cba338ff7f048a06508e2f987514125d481"]}'
{"jsonrpc":"2.0","result":{"block":{"header":{"parentHash":"0x3b761bd2ff69f4fe670c0f0911b6de1d83ee615830aed0693421f9d95fcde6e3","number":"0x1","stateRoot":"0x55a6d4664a0bccd89e68e60b7de8644121ce03094fb0caa13a84490ab396191c","extrinsicsRoot":"0x03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314","digest":{"logs":["0x0661757261203ac5602100000000","0x05617572610101c6dcdb663e80f4d02c07f0d2266b24339a514e3e41c155e65eae978ec051e64d1978f647c12a6c2022feb2b9e2c7e1959ed1fb849b1cb2294dab729f4942248e"]}},"extrinsics":[]},"justifications":null},"id":1}
Then I try to make the exact same call from Rust code, and I get an error. I'm not clear how my two requests are different or how to debug further.
use jsonrpsee::{
core::client::ClientT,
http_client::HttpClientBuilder,
rpc_params,
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = HttpClientBuilder::default().build("http://localhost:9933")?;
let s = String::from("505914d65fcf1049e630441127ca8cba338ff7f048a06508e2f987514125d481");
let params = rpc_params!{s};
let rpc_response: Result<Option<String>, _> = client.request("chain_getBlock", params).await;
match rpc_response {
Ok(Some(s)) => println!("ok some {s}"),
Ok(None) => println!("ok none"),
Err(e) => println!("%%%Error: {e:?}"),
};
Ok(())
}
The output from that Rust code is:
%%%Error: ParseError(Error("invalid type: map, expected a string", line: 1, column: 0))