# Help with PocketIC intercanister calls

**URL:** <https://forum.dfinity.org/t/help-with-pocketic-intercanister-calls/32517>\
**Category:** Developers\
**Created:** [June 29, 2024, 8:37pm UTC](https://forum.dfinity.org/t/help-with-pocketic-intercanister-calls/32517 "2024-06-29T20:37:07Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gekctek](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gekctek/32/6863_2.png) [@Gekctek](https://forum.dfinity.org/u/Gekctek)\
**Post date:** [June 29, 2024, 8:37pm UTC](https://forum.dfinity.org/t/help-with-pocketic-intercanister-calls/32517/1 "2024-06-29T20:37:07Z")

</div>

I am using PocketIC (js implementation) to test my app but i am having an issue with inter canister calls. In my ‘league’ canister I import my ‘teams’ canister with `import TeamsActor "canister:teams";` which I THINK is causing an issue when running my pocketic tests

I get an error: `Error: No route to canister bw4dl-smaaa-aaaaa-qaacq-cai`  
When making a call to the league, which then calls the teams. I believe this is due to the WASM being built has the canister id stamped in it? Then when i go to use pocketic instead of using its ids

```auto
League cansiter id lxzze-o7777-77777-aaaaa-cai
Teams cansiter id lqy7q-dh777-77777-aaaaq-cai

```

its trying to use the one from my local replica subnet

```auto

  "teams": {
    "local": "bw4dl-smaaa-aaaaa-qaacq-cai"
  },

```

Im not sure how to get around this issue  
Any help would be great

---

<div class="post-metadata">

**Author:** ![Gekctek](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gekctek/32/6863_2.png) [@Gekctek](https://forum.dfinity.org/u/Gekctek)\
**Post date:** [June 29, 2024, 8:38pm UTC](https://forum.dfinity.org/t/help-with-pocketic-intercanister-calls/32517/2 "2024-06-29T20:38:38Z")

</div>

Here is a link to my tests

> <https://github.com/edjCase/daoball/blob/main/src/frontend/test/pocket-ic/scenario.test.ts>

---

<div class="post-metadata">

**Author:** ![Gekctek](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gekctek/32/6863_2.png) [@Gekctek](https://forum.dfinity.org/u/Gekctek)\
**Post date:** [June 30, 2024, 12:00am UTC](https://forum.dfinity.org/t/help-with-pocketic-intercanister-calls/32517/3 "2024-06-30T00:00:01Z")

</div>

I have confirmed that this is the issue by manually updating the canister\_ids.json to what pocketic gives me

The options i see are:

- modify the WASM bytes on test runs
- set the canister ids to what is in local (doesn’t seem possible after testing)
- run a dfx build in a test run
- remove the canister imports and have each actor take as params the other canister ids. This seems like a real pain, but possible

---

<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:** [June 30, 2024, 8:02am UTC](https://forum.dfinity.org/t/help-with-pocketic-intercanister-calls/32517/4 "2024-06-30T08:02:52Z")

</div>

There is `targetCanisterId` for `setupCanister` but according doc it can only be used on Bitcoin, Fiduciary, II, SNS and NNS subnets.

Maybe another workaround is to use that option and use one of those subnets for your tests?

---

<div class="post-metadata">

**Author:** ![Gekctek](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gekctek/32/6863_2.png) [@Gekctek](https://forum.dfinity.org/u/Gekctek)\
**Post date:** [July 1, 2024, 4:48am UTC](https://forum.dfinity.org/t/help-with-pocketic-intercanister-calls/32517/5 "2024-07-01T04:48:43Z")

</div>

No luck

I went with no canister imports and instead making all the actors into actor classes then passing in the cansiter ids. Had to break it up and create all the canisters first, then do the install, but seems to be working. It actually solved a few other issues i was having with cyclical canister references, but it seems like you should be able to import the canisters and have it work

Problem is, im not sure how to handle my dfx builds/deploys without doing a custom script to get the proper canisterids based on the environment  
Is there a way to do canister install args that are environment specific?

---

<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:** [July 1, 2024, 5:23am UTC](https://forum.dfinity.org/t/help-with-pocketic-intercanister-calls/32517/6 "2024-07-01T05:23:08Z")

</div>

> [@Gekctek](#):
>
> Is there a way to do canister install args that are environment specific?

I cannot help here; I have no idea about Motoko and DFX.

I’m using PicJS but have not had to set a particular canister ID when deploying a test canister so far. @NathanosDev, is that a feature that can potentially be implemented?

---

<div class="post-metadata">

**Author:** ![NathanosDev](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nathanosdev/32/7204_2.png) [@NathanosDev](https://forum.dfinity.org/u/NathanosDev)\
**Post date:** [July 1, 2024, 8:29am UTC](https://forum.dfinity.org/t/help-with-pocketic-intercanister-calls/32517/7 "2024-07-01T08:29:42Z")

</div>

> I’m using PicJS but have not had to set a particular canister ID when deploying a test canister so far. @NathanosDev, is that a feature that can potentially be implemented?

Unfortunately, there’s is a feature mismatch between PocketIC and DFX. DFX will figure out the IDs of your canisters at build time and inject them somehow into the canister’s WASM, but PocketIC only tells you the canister ID at runtime.

There’s nothing that I can do about that in the JS library, it’s something that needs to be solved by the core PocketIC server.

> I went with no canister imports and instead making all the actors into actor classes then passing in the cansiter ids. Had to break it up and create all the canisters first, then do the install, but seems to be working. It actually solved a few other issues i was having with cyclical canister references, but it seems like you should be able to import the canisters and have it work

So I’m a bit late now since you already figured this out, but for future reference there’s a Motoko multicanister example project in the pic-js repo that demonstrates the cleanest approach to solving this problem that I could find: [pic-js/examples/multicanister at main · hadronous/pic-js · GitHub](https://github.com/hadronous/pic-js/tree/main/examples/multicanister).

> Problem is, im not sure how to handle my dfx builds/deploys without doing a custom script to get the proper canisterids based on the environment  
> Is there a way to do canister install args that are environment specific?

@Vivienne do you know if there’s a way to reference the canister IDs through the enviornment variables that are written to the `.env` file by DFX in the canister’s init args in `dfx.json`?

---

<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:** [July 1, 2024, 8:54am UTC](https://forum.dfinity.org/t/help-with-pocketic-intercanister-calls/32517/8 "2024-07-01T08:54:19Z")

</div>

dfx currently has no way to interpret `init_arg`. Your two options are:

Use `init_arg_file` instead of `init_arg` in dfx.json. Then you can have a build script inject the right canister IDs to that file from a template

Or dynamically construct the arg for `dfx canister install --argument '(...)'`

---

<div class="post-metadata">

**Author:** ![mraszyk](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/mraszyk/32/7945_2.png) [@mraszyk](https://forum.dfinity.org/u/mraszyk)\
**Post date:** [July 1, 2024, 8:58am UTC](https://forum.dfinity.org/t/help-with-pocketic-intercanister-calls/32517/9 "2024-07-01T08:58:08Z")

</div>

> There is `targetCanisterId` for `setupCanister` but according doc it can only be used on Bitcoin, Fiduciary, II, SNS and NNS subnets.

We’re working on making it work for all IC mainnet canister IDs. I’m confident that this feature will be available in the next PocketIC release in a week or two.

---

<div class="post-metadata">

**Author:** ![Gekctek](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gekctek/32/6863_2.png) [@Gekctek](https://forum.dfinity.org/u/Gekctek)\
**Post date:** [July 1, 2024, 4:42pm UTC](https://forum.dfinity.org/t/help-with-pocketic-intercanister-calls/32517/10 "2024-07-01T16:42:42Z")

</div>

Thanks for the responses  
Sounds like I’m going to go for a custom build script vs dfx while having all the canister ids as canister parameters
