Does anyone know how to use the Rust CDK call function?
I’m trying to call the management canister to create a new canister from wasm. It looks like I just need to implement the ArgumentEncoder trait on my struct, but it feels a bit laborious to do that for all my types.
ArgumentEncoder is implemented for all tuple types (T1, T2, ...), where Ti: CandidType. If you have a custom struct, you only need to #[derive(CandidType, Deserialize)], then pass in args as a tuple, for example (your_struct, 42, "Text").
Hey @chenyan - I’m having issues with ArgumentDecoder now. If its not too much hassle, could share an example of just calling a canister, and getting the result?
I don’t understand the question here. What do you mean by “successfully executes, but the actual call is not performed”? Are you getting the return blob from call_raw?
The canister I’m calling to is logging every request it receives and my example request should also change its state (it is an update call).
When the second canister executes a code from the snippet, the first canister does not log a request and does not change its state as well. The response the second canister receives from that call is not Err, so it looks like everything should be all right, but it’s not.
I was thinking, am I encoding arguments correctly?
Or another possible issue: maybe the response is not Err but it returns an encoded error in the Ok variant?
You can use didc decode to inspect the return blob. Or if you know how many values the function returns, you can decode in Rust via Decode!(&result, IDLValue, IDLValue, ...)?
call_raw looks good to me, I think the problem might be on the other canister, where it doesn’t actually log every requests. So looking at the return result might help.
error[E0277]: the trait bound `i32: ArgumentEncoder` is not satisfied
--> canisters/graphql/src/graphql.rs:24:157
|
24 | ...aaba-cai").unwrap(), "customGet", (number)).await;
| ^^^^^^^^ the trait `ArgumentEncoder` is not implemented for `i32`
|
::: /home/lastmjs/.cargo/registry/src/github.com-1ecc6299db9ec823/ic-cdk-0.3.0/src/api/call.rs:260:22
|
260 | pub async fn call<T: ArgumentEncoder, R: for<'a> ArgumentDecoder<'a>>(
| --------------- required by this bound in `sudograph::ic_cdk::call`
If I try just text or numbers as arguments to the call, nothing works. Is there some import I am missing?