How to pass arguments when creating canister in rust

Hello Dears!

How to pass arguments when creating canister programmatically like below?
May I wrongly formatting arguments
Or is there any other way to pass arguments when initialization canister programmatically?

let install_config = CanisterInstall {
    canister_id: canister_id.clone(),
    wasm_module: wasm_module.clone(),
    args: b"(arg1, arg2)".to_vec()  // What is the argument's format?
api::call::call(Principal::management_canister(), "install_code", (install_config,)).await...

That depends on your canister code in wasm_module :slight_smile:

Here is the init function args
fn init(name: String, symbol: String, decimals: u64, total_supply: u64)
how to pass these arguments?

I assume this means that the init function is expecting Candid encoded arguments? (I don’t know the Rust CDK well).

In that case, encode your arguments as well using the Candid library. Something like Encode!(&(arg1, arg2)) or so.


Yep, I will try this

I used encode_args() for arguments like this:

use ic_cdk::export::candid::{encode_args};

let canister_args_result = encode_args(("MyName", "MN", 18 as u64, 0 as u64));
let canister args = match canister_args_result {
    Ok(res) => res,
    _ => Vec::new()

And it works!
Thank you @nomeata