Deployment Arguments via dfx.json

It would be wonderful is we we could pass arguments via dfx.json.

Take for instance the following example:

{
  "canisters": {
    "foo_bar_baz": {
      "main": ".....",
      "type": "motoko"
      "args" : {
        "ic" : "(record { prod = true; foo = "bar real" }, 123)",
        "staging" : "(record { prod = false; foo = "bar fake" }, 452)",
        "local" : "(record { prod = true; foo = "bar fake" }, 222)",
      },
    },
  "networks": {
    "staging": {
      "providers": [
        "https://ic0.app"
      ],
      "type": "persistent"
    },
    "local": {
      "bind": "127.0.0.1:8000",
      "type": "ephemeral"
    }
  },
  "version": 1
}
3 Likes

It would be wonderful if we could pass arguments via dfx.json**

Getting errors editing the post…

3 Likes

+1, this would be really helpful!

1 Like

Yes and the ability to reference a .did file as the value for the “args” key

EDIT: I was wrong. See posts below instead There is the field canisters.<canister name>.args in dfx.json that takes a string with a candid argument inside to use when deploying the canister. Is this sufficient or is it necessary to have network-specific arguments?

Which option do you mean exactly?

  • Accept a file path as part of dfx.json’s canisters.<canister name>.args field or
  • Ability to specify dfx deploy --argument-file?
3 Likes

Is args supposed to be working in dfx 0.17.0? I don’t think I’ve ever had this work actually:

        "evm_rpc": {
            "type": "custom",
            "candid": "https://github.com/internet-computer-protocol/ic-eth-rpc/releases/latest/download/evm_rpc.did",
            "wasm": "https://github.com/internet-computer-protocol/ic-eth-rpc/releases/latest/download/evm_rpc_dev.wasm.gz",
            "specified_id": "be2us-64aaa-aaaaa-qaabq-cai",
            "args": "(record { nodesInSubnet = 28 })",
            "remote": {
                "id": {
                    "ic": "a6d44-nyaaa-aaaap-abp7q-cai"
                }
            }
        }

With dfx deploy I get

Installing canisters...
Error: Failed while trying to deploy canisters.
Caused by: Failed while trying to deploy canisters.
  Failed while trying to install all canisters.
    Failed to install wasm module to canister 'evm_rpc'.
      Failed to create argument blob.
        Invalid data: Expected arguments but found none.

Turns out I’m bad at reading our own code. Quoting from the dfx.json schema:

init_arg: The Candid initialization argument for installing the canister. If the --argument or --argument-file argument is also provided, this init_arg field will be ignored.

args: This field defines an additional argument to pass to the Motoko compiler when building the canister.

So you have to use init_arg instead of args

1 Like

Works! Thanks so much

1 Like

Is there any way to put shell escapes into init_arg like I would use $(dfx canister id <name>) in a dfx deploy command? Or some other way to achieve a “dynamic” init_arg?

1 Like

I am also very interested in this functionality

Right now we don’t have a way to make arguments dynamic, but we’ve shortlisted this feature request as one of the things we want to do in the very near future (although not scheduled yet)