# Rust Canister initializing with value

**URL:** <https://forum.dfinity.org/t/rust-canister-initializing-with-value/20830>\
**Category:** Developers\
**Created:** [June 19, 2023, 11:43pm UTC](https://forum.dfinity.org/t/rust-canister-initializing-with-value/20830 "2023-06-19T23:43:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcpim](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tcpim/32/5916_2.png) [@tcpim](https://forum.dfinity.org/u/tcpim)\
**Post date:** [June 19, 2023, 11:43pm UTC](https://forum.dfinity.org/t/rust-canister-initializing-with-value/20830/1 "2023-06-19T23:43:13Z")

</div>

I want to use the same code to deploy multiple canisters. dfx.json looks like

```auto
{
  "canisters": {
    "canister_1": {
      "candid": "same path",
      "package": "same path",
      "type": "rust"
    },
    "canister_2": {
      "candid": "same path",
      "package": "same path",
      "type": "rust"
    },
    "canister_3": {
      "candid": "same path",
      "package": "same path",
      "type": "rust"
    }
  },
  "defaults": {
    "build": {
      "args": "",
      "packtool": ""
    }
  },
  "dfx": "0.14.1",
  "version": 1
}

```

I have a stable structure

```auto
    pub static CANISTER_INFO: RefCell<StableCell<CanisterInfo, Memory>> =
        MEMORY_MANAGER.with(|memory_manager|
            RefCell::new(
                StableCell::init(memory_manager.borrow().get(CANISTER_INFO_MEMORY_ID), CanisterInfo 
         {
                name: "".to_string(),
            }).expect("Failed to init CANISTER_INFO")
            )
        );

```

Is there a way to somehow initialize the CanisterInfo.name field when deploying all the canisters? The name can be the same with the canister name specified in dfx.json. Worst case, I could call a API to set the name after deployment for each canister. But since I will have many canisters, doing that during development is a pain

---

<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:** [June 20, 2023, 5:45am UTC](https://forum.dfinity.org/t/rust-canister-initializing-with-value/20830/2 "2023-06-20T05:45:20Z")

</div>

At some point I’d like to see a field `argument_file` for canisters so you can point all of them at the same file and you’re good to go. Until then, I think the easiest solution is to write a script that calls `dfx deploy` with the same `--argument <...>` for every canister

---

<div class="post-metadata">

**Author:** ![tcpim](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tcpim/32/5916_2.png) [@tcpim](https://forum.dfinity.org/u/tcpim)\
**Post date:** [June 20, 2023, 10:13pm UTC](https://forum.dfinity.org/t/rust-canister-initializing-with-value/20830/3 "2023-06-20T22:13:54Z")

</div>

Thanks. I was not aware that there is a `--argument` option. Two questions

1. Say I have a candid file (the actual code is more complex so I simply the request type)

```auto
type SetCanisterInfoRequest = record {
  name : text;
};
service : {
  set_canister_info : (SetCanisterInfoRequest) -> ();
}

```

I tried `dfx canister call test_canister set_canister_info '(record { name="hey" })' ` and I got

```auto
Error: Failed to create argument blob.
Caused by: Failed to create argument blob.
  Invalid data: Unable to serialize Candid values: Invalid data: Unable to serialize Candid values: record field info not found

```

Did I miss anything? I followed the example here [Internet Computer Loading](https://internetcomputer.org/docs/current/developer-docs/backend/rust/rust-profile#call-functions-on-the-deployed-canister)

1. When using `dfx deploy test_canister --argument=` as you suggested, what should I put in the argument using the example above? The official doc says

`Specifies an argument using Candid syntax to pass to the canister during deployment. Note that this option requires you to define an actor class in the Motoko program.`

but I still don’t understand. Are you aware of any example of this argument usage?

---

<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:** [June 21, 2023, 7:39am UTC](https://forum.dfinity.org/t/rust-canister-initializing-with-value/20830/4 "2023-06-21T07:39:08Z")

</div>

> [@tcpim](#):
>
> I tried `dfx canister call test_canister set_canister_info '(record { name="hey" })'`

Looks completely fine to me. Really stupid question: did you save the candid file and point at it properly? It sounds like it’s expecting a different record that includes a field called `info`

> [@tcpim](#):
>
> When using `dfx deploy test_canister --argument=` as you suggested, what should I put in the argument using the example above?

If your canister takes `SetCanisterInfoRequest` as an init argument then you’d simply call `dfx deploy test_canister --argument='(record { name="hey" })'`

---

<div class="post-metadata">

**Author:** ![tcpim](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tcpim/32/5916_2.png) [@tcpim](https://forum.dfinity.org/u/tcpim)\
**Post date:** [June 21, 2023, 6:17pm UTC](https://forum.dfinity.org/t/rust-canister-initializing-with-value/20830/5 "2023-06-21T18:17:12Z")

</div>

Thanks. I just passed the wrong record. Now it is working
