I have a migration file as follows. I am trying to deploy a new instance of an already deployed contract using the overwrite parameter, however truffle gives me the error:
Error: Invalid number of parameters for "undefined". Got 2 expected 1!
Apparently trying to use the options object as an argument.
```
module.exports = async function (deployer, network, accounts) {
const contractAInstance = await A.deployed();
const contractBInstance = await B.deployed();
await contractBInstance.setOperator(contractAInstance.address, false);
await deployer.deploy(A, contractBInstance.address, { overwrite: true });
};
Update
Adding from to the options object makes the error go away
await deployer.deploy(A, contractBInstance.address, { from: accounts[0] overwrite: true });
However I'd expect a new address to be given when asking for the deployed contract, but the new instance gives the same address as the old.
const oldInstance = await A.deployed();
await deployer.deploy(A, contractBInstance.address, { from: accounts[0] overwrite: true });
const newInstance = await A.deployed();
// newInstance.address is the same as the instance before using overwrite: true
// oldInstance.address === newInstance.address
Hey @pizza-r0b , it looks like you're trying to re-migrate a contract. What are you attempting to do with the overwrite property? I don't believe it's a valid truffle-related option. Have you tried using truffle migrate --reset? https://www.trufflesuite.com/docs/truffle/getting-started/running-migrations#command.
Can you share a repo with reproduction steps?
@CruzMolina I am trying to re-deploy a new instance of only that contract.
I think I may be using overwrite incorrectly. The docs don't do a great job explaining this.
Additionally, the last argument is an optional object that can include the key named overwrite as well as other transaction parameters such as gas and from. If overwrite is set to false, the deployer won't deploy this contract if one has already been deployed.
But I imagine I can use --reset and specify overwrite: false on all the contracts in which I do not want to be overwritten.
Ah, I see. Yeah I believe there's two bugs here, one when using the overwrite (it should be acceptable to only pass that as an extra param, not needing other args like from), and another with the address not being properly reset on a new deployed contract instance.
What is the overwrite option? Can anyone link to some docs?
@eggplantzzz https://www.trufflesuite.com/docs/truffle/getting-started/running-migrations#deployer-deploy-contract-args-options-
@CruzMolina I think you are correct about the bugs
I wonder if it's a problem with the code that detects whether the last parameter is an options. It might look for from specifically to make that determination.
Might want to look at this one at the same time as #2868
The problem is here:
overwrite is not one of the flags that Truffle looks for to identify an options object.
I found this issue because we ran into it when the options object is empty. (https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/213)
It's easy to add the overwrite flag to the list above, but an empty object won't be detected with the current approach. Maybe there should be a special case for empty objects, and always consider it a params object.
Ah thanks @frangio for the info. I'll take a look into this and see about adding a fix!
overwrite was added to the whitelist in version 5.1.58! Thanks @frangio!