Using https://hardhat.org/plugins/hardhat-deploy.html, how do you get extra values into the deploy code? For example, given the example code:

// deploy/00_deploy_my_contract.js
module.exports = async ({getNamedAccounts, deployments}) => {
  const {deploy} = deployments;
  const {deployer} = await getNamedAccounts();
  await deploy('MyContract', {
    from: deployer,
    args: ['Hello'],
    log: true,
module.exports.tags = ['MyContract'];

Is there a standard hardhat-deploy system for replacing the static 'Hello' with something dynamic? Something like getNamedAccounts, but not specifically for accounts, for example. Or is this just the sort of thing where you use standard Javascript tools to get the values into the code?

  • Did you manage to find out anything about this? I'm also looking for a solution on this.
    – xenon
    Nov 16, 2021 at 5:31
  • @xenon finally decided that hardhat-deploy wasn't useful for what we were doing, so I didn't investigate more. Nov 16, 2021 at 20:45
  • I don't understand this question. If you want to replace 'Hello' with something else, then why not just replace it? Or if you are talking specifically about using deployment scripts from tests via deployments.fixture(), then please state that explicitly. Dec 30, 2021 at 18:45
  • @AdamSpiers sometimes it's hard to formulate questions properly when we aren't experts of a specific library. I'd also like to get an answer to this question, both for test fixtures, but also for other kinds of "normal" deployments (is it possible to pass arguments to npx hardhat deploy for eg.?) I just asked the question here: github.com/wighawag/hardhat-deploy/issues/289
    – samlaf
    Mar 14, 2022 at 22:27

2 Answers 2


Or is this just the sort of thing where you use standard Javascript tools to get the values into the code?

Yes, this exactly. This is JS. If you need a programatic/dynamic value instead of a static value, write JS, e.g.:

    args: [Math.random()+""],

If you don't want to write it in JS for some reason, then take this as a string and dynamically output the JS with your tool of choice.


you can use deploy-scripts to specify deploy logic

export interface DeployOptions = {
  from: string; // address (or private key) that will perform the transaction. you can use `getNamedAccounts` to retrived the address you want by name.
  contract?: // this is an optional field. If not specified it defaults to the contract with the same name as the first parameter
    | string // this field can be either a string for the name of the contract
    | { // or abi and bytecode
        abi: ABI;
        bytecode: string;
        deployedBytecode?: string;
  args?: any[]; // the list of argument for the constructor (or the upgrade function in case of proxy)
  skipIfAlreadyDeployed?: boolean; // if set it to true, will not attempt to deploy even if the contract deployed under the same name is different
  log?: boolean; // if true, it will log the result of the deployment (tx hash, address and gas used)
  linkedData?: any; // This allow to associate any JSON data to the deployment. Useful for merkle tree data for example
  libraries?: { [libraryName: string]: Address }; // This let you associate libraries to the deployed contract
  proxy?: boolean | string | ProxyOptions; // This options allow to consider your contract as a proxy (see below for more details)

  // here some common tx options :
  gasLimit?: string | number | BigNumber;
  gasPrice?: string | BigNumber;
  value?: string | BigNumber;
  nonce?: string | number | BigNumber;

  estimatedGasLimit?: string | number | BigNumber; // to speed up the estimation, it is possible to provide an upper gasLimit
  estimateGasExtra?: string | number | BigNumber; // this option allow you to add a gas buffer on top of the estimation

  autoMine?: boolean; // this force a evm_mine to be executed. this is useful to speed deployment on test network that allow to specify a block delay (ganache for example). This option basically skip the delay by force mining.
  deterministicDeployment? boolean | string; // if true, it will deploy the contract at a deterministic address based on bytecode and constuctor arguments. The address will be the same across all network. It use create2 opcode for that, if it is a string, the string will be used as the salt.

args field in the above snippet is for the list of argument for the constructor (or the upgrade function in case of proxy)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.