wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.18k stars 286 forks source link

Multiple deploys per artifact name #381

Closed zfogg closed 1 year ago

zfogg commented 1 year ago

Hi! Basically I want to deploy multiple instances of the same contract, but with different constructor arguments. It would look something like this:

module.exports = async ({getNamedAccounts, deployments, ethers}) => {
  const { deployer } = await getNamedAccounts()

  // first instance
  const deploy1 = await deployments.deploy('SomeContract', {
    from: deployer,
    args: ['0xff'],
    log: true,
  })

  // second instance
  const deploy2 = await deployments.deploy('SomeContract', {
    from: deployer,
    args: ['0x00'],
    log: true,
  })
}

and then later I want to reference them in scripts like await deployments.get('SomeContract'), however the second instance seems to overwrite the first instance, correct? how can i deploy with hardhat-deploy and this artifact system while still being able to reference multiple contracts deployed in this way? should i just go back to using ethers.getContractFactory and saving my own json files?

zfogg commented 1 year ago

i actually fixed this out for myself! You need to do like this:

module.exports = async ({getNamedAccounts, deployments, ethers}) => {
  const { deployer } = await getNamedAccounts()

  // first instance
  const deploy1 = await deployments.deploy('SomeContract-something', {
    contract: 'SomeContract',
    from: deployer,
    args: ['0xff'],
    log: true,
  })

  // second instance
  const deploy2 = await deployments.deploy('SomeContract-somethingElse', {
    contract: 'SomeContract',
    from: deployer,
    args: ['0x00'],
    log: true,
  })
}

:) note the contract field in the options object