Rust ic_cdk: Minimal example of passing argument to `main::install_code` and decoding inside the target canister

Hey, I’ve played with this before. Here’s how I handled it:

  1. In code, from rust to rust. You can create a struct however you’d like, and pass it in install_code, like so: quickstart_scaling/businesslogic.rs at 3c9a65ee19c0fa458d4ddc8582c76d7bd6dbdbdf · GLicDEV/quickstart_scaling · GitHub

On the receiving side, you get it like so: quickstart_scaling/lifetime.rs at 3c9a65ee19c0fa458d4ddc8582c76d7bd6dbdbdf · GLicDEV/quickstart_scaling · GitHub

  1. For compatibility with dfx, and for automatic did generation, you can append your init function with the proper macro, as described here: How to pass install arguments from dfx?

Hope this helps

1 Like