pub fn call_with_config<'b, T: ArgumentEncoder, R: for<'a> ArgumentDecoder<'a>>(
id: Principal,
method: &'b str,
args: T,
cycles: u128,
arg_config: &'b ArgDecoderConfig,
) -> impl Future<Output = CallResult<R>> + Send + Sync + 'b
Expand description
Performs an asynchronous call to another canister and pay cycles (in u128
).
It also allows setting a quota for decoding the return values.
The decoding quota is strongly recommended when calling third-party or untrusted canisters.
ยงExample
Assuming that the callee canister has following interface:
service : {
add_user: (name: text) -> (nat64);
}
It can be called:
async fn call_add_user() -> u64 {
let config = ArgDecoderConfig {
// The function only returns a nat64, to accomodate future upgrades, we set a larger decoding_quota.
decoding_quota: Some(10_000),
// To accomodate future upgrades, reserve some skipping_quota.
skipping_quota: Some(100),
// Enable debug mode to print decoding instructions and cost to the replica log.
debug: true,
};
let (user_id,) = call_with_config(callee_canister(), "add_user", ("Alice".to_string(),), 1_000_000u128, &config).await.unwrap();
user_id
}