Create canister in runtime

Hi! I have a canister, which performs some logic. So I need create another canister instance in runtime. What I am doing.

  1. Getting wasm code of current canister
  2. Perform call for canister creation where controllers same as, controllers of current canister
let create_res = create_canister(
        CreateCanisterArgument {
            settings: Some(CanisterSettings {
                controllers: Some(ctls),
                compute_allocation: None,
                memory_allocation: None,
                freezing_threshold: None,
                reserved_cycles_limit: None,
            }),
        },
        15_000_000_000,
    )
  1. Passing arguments, wasm and controllers to the install_wasm method
let arg = InstallCodeArgument {
        mode: CanisterInstallMode::Install,
        canister_id: cnstr,
        wasm_module: wasm_vec.clone(),
        arg: argument,
    };

    let res = install_code(arg).await;

So, canister successfually creates and works. But, when I am trying to navigate to this canister via candid interface 127.0.0.1:4943/?canisterId=bd3sg-teaaa-aaaaa-qaaba-cai&id=b77ix-eeaaa-aaaaa-qaada-cai where b77ix-eeaaa-aaaaa-qaada-cai is id of recently created canister, I receive following error

An error happened in Candid canister:
Error: Cannot fetch candid file
    at fetchActor (127.0.0.1:4943/index.js:2:319660)
    at async 127.0.0.1:4943/index.js:2:329683

How can I pass did file to newly created canister? Or, probably I need to recompile wasm correctly. Should wasm contain did file?

For candid UI to be able to pick up the interface it needs to be in a public candid:service metadata section of the wasm

Thanks for your reply! So, how to check if candid:service metadata present in metadata? So, I just do dfx deploy for canister, so wasm file appears automaticaly. So, I added ‘candid:service’ to my source canister

"send_http_get_rust_backend": {
      "candid": "src/send_http_get_rust_backend/send_http_get_rust_backend.did",
      "package": "send_http_get_rust_backend",
      "type": "rust",
      "metadata": [
        {
          "name": "candid:service"
        }
      ]
    }

But I have same exception. How to add metadata to wasm? Or how to check that metadata present in wasm? Thanks!

This should work. To check a compiled wasm you can with cargo install ic-wasm: ic-wasm <file> metadata. And once the wasm is installed you can check with dfx canister metadata <canister> candid:service