Function ic_cdk::api::call::call_with_payment
source · pub fn call_with_payment<T: ArgumentEncoder, R: for<'a> ArgumentDecoder<'a>>(
id: Principal,
method: &str,
args: T,
cycles: u64,
) -> impl Future<Output = CallResult<R>> + Send + Sync
Expand description
Performs an asynchronous call to another canister and pay cycles at the same time.
§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 (user_id,) = call_with_payment(callee_canister(), "add_user", ("Alice".to_string(),), 1_000_000u64).await.unwrap();
user_id
}
§Note
- Both argument and return types are tuples even if it has only one value, e.g
(user_id,)
,("Alice".to_string(),)
. - The type annotation on return type is required. Or the return type can be inferred from the context.
- The asynchronous call must be awaited in order for the inter-canister call to be made.
- If the reply payload is not a valid encoding of the expected type
T
, the call results in RejectionCode::CanisterError error.