# Pass constructor arguments in dfx.json?

**URL:** <https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246>\
**Category:** Developers\
**Created:** [December 2, 2021, 3:04am UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246 "2021-12-02T03:04:56Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![spencer](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@spencer](https://forum.dfinity.org/u/spencer)\
**Post date:** [December 2, 2021, 3:04am UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246/1 "2021-12-02T03:04:56Z")

</div>

Is it possible to pass a default constructor argument for my canister into dfx.json, so that when I simply call dfx deploy, that argument is passed in without specifying it?

Example:  
“mycanister”:{  
“main”:“src/mycanister.mo”,  
“type”:“motoko”,  
“argument”:"(12345)"  
}

Is this something that could be added in the future?

---

<div class="post-metadata">

**Author:** ![gajendraks](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gajendraks/32/4252_2.png) [@gajendraks](https://forum.dfinity.org/u/gajendraks)\
**Post date:** [February 24, 2022, 6:39am UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246/2 "2022-02-24T06:39:08Z")

</div>

Do we have a documentation on all the possible entries of dfx.json and what we can achieve with different entries in dfx.json.

Please can someone point us to the documentation/resource if any?

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [February 24, 2022, 8:29am UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246/3 "2022-02-24T08:29:46Z")

</div>

@chiedo was also looking and found this.

> [@Questions around dfx.json and request for improved dfx.json docs](https://forum.dfinity.org/t/questions-around-dfx-json-and-request-for-improved-dfx-json-docs/10462/3):
>
> For anyone else who reads this, this seems to mostly explain the dfx.json config.

---

<div class="post-metadata">

**Author:** ![gajendraks](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gajendraks/32/4252_2.png) [@gajendraks](https://forum.dfinity.org/u/gajendraks)\
**Post date:** [February 24, 2022, 4:54pm UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246/4 "2022-02-24T16:54:58Z")

</div>

I agree that document([Customize the front-end :: Internet Computer](https://smartcontracts.org/docs/developers-guide/tutorials/custom-frontend.html#_review_the_default_configuration)) helps.

But it describes less number of options out of all the options that can be passed to dfx.json  
I need info about the all the options.

Thanks

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [February 24, 2022, 8:09pm UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246/5 "2022-02-24T20:09:04Z")

</div>

I don’t think it’s documented but you should be able to figure it out from here:

> <https://github.com/dfinity/sdk/blob/458abd206c30ecd98e5448e35803ddfbd1344063/src/dfx/src/config/dfinity.rs#L169-L176>

---

<div class="post-metadata">

**Author:** ![gajendraks](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gajendraks/32/4252_2.png) [@gajendraks](https://forum.dfinity.org/u/gajendraks)\
**Post date:** [February 25, 2022, 12:54am UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246/6 "2022-02-25T00:54:32Z")

</div>

This helps, thank you.  
But please someone document as it helps many.

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [January 21, 2023, 4:17pm UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246/7 "2023-01-21T16:17:46Z")

</div>

Did we ever figure out exactly what the argument looks like and if this works? And can it be specified by network?

---

<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:** [January 23, 2023, 8:56am UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246/8 "2023-01-23T08:56:06Z")

</div>

I just had a glance over the definition, and I have to disappoint you. There is an `argument` field per canister (defined [here](https://github.com/dfinity/sdk/blob/master/src/dfx/src/config/dfinity.rs#L137-L139)), but it says `This field defines an additional argument to pass to the Motoko compiler when building the canister.` and it can’t be specified per network.

---

<div class="post-metadata">

**Author:** ![icaten](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icaten/32/9897_2.png) [@icaten](https://forum.dfinity.org/u/icaten)\
**Post date:** [January 24, 2023, 2:11am UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246/9 "2023-01-24T02:11:20Z")

</div>

While not quite what was asked, the [zx](https://github.com/google/zx) “CLI devops scripting” tool might be useful to do this and some other things (like automatically switch which system-wide `networks.json` configuration is used (@jorgenbuilder)).

Eg:

`dfxd.mjs`

```auto
#!/usr/bin/env z
import { argv, chalk } from "zx";
import { spawnSync } from "child_process"

console.info(chalk.bgBlue("restarting dfx clean"))
// stop currently any currently running 
await $`dfx stop`
// can be done other ways (https://github.com/google/zx/discussions/371)
spawnSync(
    'dfx',
    ['start', '--clean', '--background'],
    { 
        detached: true,
        stdio: 'ignore' // if you want to send output elsewhere
    }
)

if (argv.argDeploy) {
    console.info(chalk.bgGreen("\ndeploying with arg!\n"))
    await $`dfx depoy acanister --argument '( record { invokePerpetualProtocol = true; numOfDerivations = 1_001; etc etc } )'`
} else {
    console.info(chalk.bgCyan("\nnot deploying with arg!\n"))
    await $`dfx deploy acanister`
}

console.info(chalk.bgBlue("\nCanister deployed...\n"))

```

And in a console:

`> $zx ./dfxd.mjs --argDeploy`

If you do end up using zx, [be aware](https://github.com/google/zx/issues/547) it does its own string escaping which will definitely interfere if you want to use template literals to build compound expressions involving dfx. A simple way to bypass this is add:

`$.quote = (...all) => all`

To the top of your script.

---

<div class="post-metadata">

**Author:** ![Dustin](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@Dustin](https://forum.dfinity.org/u/Dustin)\
**Post date:** [August 9, 2023, 2:53pm UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246/10 "2023-08-09T14:53:23Z")

</div>

Is there by now an option available to specify deploy arguments in the dfx.json file? Something like what was described [here](https://forum.dfinity.org/t/deployment-arguments-via-dfx-json/9702).

---

<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:** [August 10, 2023, 8:19am UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246/11 "2023-08-10T08:19:31Z")

</div>

No, still not available

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [March 2, 2024, 12:12am UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246/12 "2024-03-02T00:12:15Z")

</div>

Linking, is this available now or planned? The comment above mine makes it sound like this functionality is available: [Deployment Arguments via dfx.json - #6 by lastmjs](https://forum.dfinity.org/t/deployment-arguments-via-dfx-json/9702/6)

---

<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 4, 2024, 12:30pm UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246/13 "2024-03-04T12:30:48Z")

</div>

As of 0.17.0 [it is available](https://github.com/dfinity/sdk/blob/master/CHANGELOG.md#feat-init_arg-in-dfxjson) as `canisters.<canister name>.init_arg`

---

<div class="post-metadata">

**Author:** ![ZenVoich](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zenvoich/32/5969_2.png) [@ZenVoich](https://forum.dfinity.org/u/ZenVoich)\
**Post date:** [March 4, 2024, 12:46pm UTC](https://forum.dfinity.org/t/pass-constructor-arguments-in-dfx-json/9246/14 "2024-03-04T12:46:15Z")

</div>

Would be useful to have `init_arg_file` as well [Option to set init arg file in dfx.json · dfinity/sdk · Discussion #3619 · GitHub](https://github.com/dfinity/sdk/discussions/3619)
