# Need help implementing install\_code() canister method

**URL:** <https://forum.dfinity.org/t/need-help-implementing-install-code-canister-method/18313>\
**Category:** Developers\
**Created:** [January 31, 2023, 9:59pm UTC](https://forum.dfinity.org/t/need-help-implementing-install-code-canister-method/18313 "2023-01-31T21:59:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jesse](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jesse/32/37836_2.png) [@Jesse](https://forum.dfinity.org/u/Jesse)\
**Post date:** [January 31, 2023, 9:59pm UTC](https://forum.dfinity.org/t/need-help-implementing-install-code-canister-method/18313/1 "2023-01-31T21:59:03Z")

</div>

I’m trying to implement the `installCode_` method below. The canister actor that I’m trying to install the wasmModule to is constructed like so:

```auto
shared(msg) actor class Journal (principal : Principal) = this {
    //code
}

```

I’m pretty sure the issue with the implementation is with the way I’m defining the `arg` variable.

```auto
private func installCode_ (arg: Blob, wasmModule: Blob, canister_id: Principal) : async () {
        await ic.stop_canister({canister_id = canister_id});
        await ic.install_code({
            arg = arg;
            wasm_module = wasmModule;
            mode = #upgrade;
            canister_id = canister_id;
        });
        await ic.start_canister({canister_id = canister_id});
    };

```

here is how I’m defining the `arg` varibale that I pass into the `installCode_()` method:  
`let arg = Principal.toBlob(principal);`

the method is trapping at the ic.install\_code() method.  
How do I properly define the `arg` argument that is passed into the

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [February 1, 2023, 6:11am UTC](https://forum.dfinity.org/t/need-help-implementing-install-code-canister-method/18313/2 "2023-02-01T06:11:28Z")

</div>

The arg should probably be encoded to Candid. Try to encode the arg with `to_candid`.

Been a while since I did not write any Motoko but, I did that few months ago in this sample repo: [motoko\_to\_rust\_migration/main.mo at 1d51608bbea4f7257d6ed0916a5238d4427ec13b · peterpeterparker/motoko\_to\_rust\_migration · GitHub](https://github.com/peterpeterparker/motoko_to_rust_migration/blob/1d51608bbea4f7257d6ed0916a5238d4427ec13b/src/motoko_to_rust_migration_backend/main.mo#L52)

```auto
private let user: {user: Text} = {user = "David"};
...
await ic.install_code({
          arg = to_candid(user);
          wasm_module = wasmModule;
          mode = #upgrade;
          canister_id = cId;
        });

```

---

<div class="post-metadata">

**Author:** ![Jesse](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jesse/32/37836_2.png) [@Jesse](https://forum.dfinity.org/u/Jesse)\
**Post date:** [February 2, 2023, 4:10pm UTC](https://forum.dfinity.org/t/need-help-implementing-install-code-canister-method/18313/3 "2023-02-02T16:10:44Z")

</div>

> [@peterparker](#):
>
> `to_candid(user)`

this did the trick. thanks again!

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [February 2, 2023, 4:40pm UTC](https://forum.dfinity.org/t/need-help-implementing-install-code-canister-method/18313/4 "2023-02-02T16:40:11Z")

</div>

> [@Jesse](#):
>
> this did the trick. thanks again!

coolio, happy to hear that!
