# Generate bindings for remote canisters

**URL:** <https://forum.dfinity.org/t/generate-bindings-for-remote-canisters/28125>\
**Category:** Developers\
**Created:** [March 5, 2024, 9:30am UTC](https://forum.dfinity.org/t/generate-bindings-for-remote-canisters/28125 "2024-03-05T09:30:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [March 5, 2024, 9:30am UTC](https://forum.dfinity.org/t/generate-bindings-for-remote-canisters/28125/1 "2024-03-05T09:30:23Z")

</div>

I have a question about the feature explained [here](https://internetcomputer.org/docs/current/other/updates/release-notes/0.9.2-rn/#new-feature-generating-remote-canister-bindings) which is the command `dfx remote generate-binding <canister name>`. The given dfx.json example is:

```auto
{
  "canisters": {
    "<canister name>": {
      "main": "<path to mo/rs/ts/js file that will be generated>",
      "remote": {
        "candid": "<path to candid file to use when generating bindings>"
        "id": {}
      }
    }
  }
}

```

How can I build more than one bindings file? It seems I can only put one path in there so it can either be mo,rs,ts or js. What if I need two?

In other places of the dfx.json schema “main” seems to be used for an input. Here it is an output. Is that a hack?

When the canister type is “custom”, then the given example is not enough. I also need a “candid” and a “wasm” field on the level above, making the whole look like this:

```auto
{
  "canisters": {
    "<canister name>": {
      "type": "custom",
      "main": "<path to mo/rs/ts/js file that will be generated>",
      "candid": "...",
      "wasm": "....",
      "remote": {
        "candid": "<path to candid file to use when generating bindings>"
        "id": {}
      }
    }
  }
}

```

Is that intended? What if I only need the bindings, not the actual canister?

---

<div class="post-metadata">

**Author:** ![jennifertran](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jennifertran/32/11558_2.png) [@jennifertran](https://forum.dfinity.org/u/jennifertran)\
**Post date:** [March 6, 2024, 9:01pm UTC](https://forum.dfinity.org/t/generate-bindings-for-remote-canisters/28125/2 "2024-03-06T21:01:14Z")

</div>

Why do you need multiple bindings?

---

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [March 7, 2024, 5:31am UTC](https://forum.dfinity.org/t/generate-bindings-for-remote-canisters/28125/3 "2024-03-07T05:31:44Z")

</div>

Frontend code may be mixed js/ts and may need both bindings.

---

<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:** [March 8, 2024, 9:18am UTC](https://forum.dfinity.org/t/generate-bindings-for-remote-canisters/28125/4 "2024-03-08T09:18:43Z")

</div>

Short answer is you can’t. Do you have `didc` available? In that case you could `didc bind` for every type you need. It does basically the same thing

---

<div class="post-metadata">

**Author:** ![lwshang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lwshang/32/3394_2.png) [@lwshang](https://forum.dfinity.org/u/lwshang)\
**Post date:** [March 8, 2024, 2:08pm UTC](https://forum.dfinity.org/t/generate-bindings-for-remote-canisters/28125/5 "2024-03-08T14:08:08Z")

</div>

What about using the `dfx generate`?

For dfx.json as below:

```json
{
    "canisters": {
        "internet_identity": {
            "type": "custom",
            "candid": "https://github.com/dfinity/internet-identity/releases/download/release-2024-03-01/internet_identity.did",
            "wasm": "https://github.com/dfinity/internet-identity/releases/download/release-2024-03-01/internet_identity_dev.wasm.gz",
            "remote": {
                "id": {
                    "ic": "rdmx6-jaaaa-aaaaa-aaadq-cai"
                }
            },
            "declarations": {
                "bindings": [
                    "js",
                    "ts"
                ]
            },
            "frontend": {}
        }
    }
}

```

Then simply running.

```bash
dfx build --check # download wasm & candid from urls
dfx generate

```

I got both js and ts bindings in the expected directory.

---

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [March 8, 2024, 4:35pm UTC](https://forum.dfinity.org/t/generate-bindings-for-remote-canisters/28125/6 "2024-03-08T16:35:24Z")

</div>

Yes, that is one of the work-arounds I have been using.

I was just trying to speed up CI and cut out as much as possible. Adding the `dfx build` step works but should not be necessary. Or is it very fast in this case because the wasm is already supplied, i.e. no compilation happens?

didc also works as a work-around. I just wanted to skip the installation step for didc if possible.

Anyway, it’s ok to do one of the two. Just wanted to clarify what `dfx remote generate-binding` can do.

---

<div class="post-metadata">

**Author:** ![lwshang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lwshang/32/3394_2.png) [@lwshang](https://forum.dfinity.org/u/lwshang)\
**Post date:** [March 12, 2024, 2:48pm UTC](https://forum.dfinity.org/t/generate-bindings-for-remote-canisters/28125/7 "2024-03-12T14:48:36Z")

</div>

The `dfx build` step is there to make sure that the files are available locally. You only need to run it once when you add a remote canister in `dfx.json`. `dfx remote generate-binding` also needs it.

IMO, we should not have `dfx remote generate-binding`. The general `dfx generate` can cover the use cases of remote canister very well and doesn’t have the limitation you encountered.
