I’m trying to pass some arguments when installing / upgrading a canister from dfx and I can’t seem to figure it out.
In the rust canister I have this code:
#[derive(CandidType, Deserialize, Debug, Default)]
struct SendArgs {
greet: String,
}
#[init]
fn init() {
let call_arg = ic_cdk::api::call::arg_data::<(Option<SendArgs>,)>().0;
ic_cdk::print(format!("Init: {:?}", call_arg));
[...]
}
When installing the code from another rust canister, like here, this works and I can read call_arg. I just can’t seem to figure out how to send this from dfx.
Things I’ve tried:
dfx deploy ic_test --argument '(record {greet="Test"})' --mode reinstall
dfx deploy ic_test --argument '(opt record {greet="Test"})' --mode reinstall
dfx canister install --mode reinstall --argument '(opt record {greet="test"})' ic_test
All I get is
[Canister rrkah-fqaaa-aaaaa-aaaaq-cai] Init: None
I also tried arg_data::<(Option,)>() and arg_data::<(String,)>() without any success. I think the issue is with how I send the data from dfx.
For context, I’m trying to call ::arg_data from post_update, so we can use a neat pattern that @Seb showed us during the Friday call.