# Create canister in runtime

**URL:** <https://forum.dfinity.org/t/create-canister-in-runtime/40698>\
**Category:** Rust\
**Created:** [January 30, 2025, 10:21pm UTC](https://forum.dfinity.org/t/create-canister-in-runtime/40698 "2025-01-30T22:21:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maks](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Maks](https://forum.dfinity.org/u/Maks)\
**Post date:** [January 30, 2025, 10:21pm UTC](https://forum.dfinity.org/t/create-canister-in-runtime/40698/1 "2025-01-30T22:21:53Z")

</div>

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

```auto
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

```auto
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

```auto
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?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [January 31, 2025, 8:46am UTC](https://forum.dfinity.org/t/create-canister-in-runtime/40698/2 "2025-01-31T08:46:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Maks](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Maks](https://forum.dfinity.org/u/Maks)\
**Post date:** [January 31, 2025, 1:31pm UTC](https://forum.dfinity.org/t/create-canister-in-runtime/40698/3 "2025-01-31T13:31:07Z")

</div>

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

```auto
"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!

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [January 31, 2025, 1:32pm UTC](https://forum.dfinity.org/t/create-canister-in-runtime/40698/4 "2025-01-31T13:32:34Z")

</div>

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`
