it is ok to access with dfx
but fail to access with agent-rs
canister code is below:
struggling in access canister without dfx command line.
it is ok to access with dfx
but fail to access with agent-rs
canister code is below:
struggling in access canister without dfx command line.
It’s very trick in agent-rs, empty byte sequence != empty argument list.
in this case, the following non-empty bytes should be provided to indicate empty argument list.
let args = candid::Encode!().unwrap();
println!("args: {:?}", args);
the whole code is below
#[tokio::test]
async fn agent_test() {
let a = Agent::builder().with_url("http://127.0.0.1:4943").with_verify_query_signatures(false).build().unwrap();
let canister_id = Principal::from_text("bkyz2-fmaaa-aaaaa-qaaaq-cai").unwrap();
let args = candid::Encode!().unwrap();
println!("args: {:?}", args);
let result = a.query(&canister_id, "greet").with_arg(args).call().await;
match result{
Ok(response) => {
// Convert response to a string or other suitable format
println!("Response: {:?}", response); // Print the response
},
Err(e) => {
eprintln!("Error occurred: {}", e);
}
}
}