3

I have a dapp consisting of two contracts, which don't particularly have a dependency on each other or know about each other.

I want to replace one of the contracts, but not the other one. If I did truffle migrate --reset it would redeploy the one I want to keep, not to mention redeploying the "Migration" contract that it uses to keep track of what it's migrated. I thought the obvious thing to do was to make a new migration deploying the contract I'm changing and running truffle migrate without the --reset, and that seemed to work, but redeploying a contract over the previous one with the same name messed up the .json build file and caused my dapp to break expect extra function arguments that weren't there.

I think I can work through it by redeploying with a migration on mainnet, then doing a clean redeploy of the whole thing on testnet then editing the resulting build files by hand so that they know where to find the mainnet contracts, but this seems hackish and error-prone. Is there a "correct" way to do this?

3

Truffle has an overwrite flag you can use to select whether an already-deployed contract should be replaced when running migrate --reset

You can use it by including the following in your migration files:

// Don't deploy this contract if it has already been deployed
deployer.deploy(A, {overwrite: false});

In your case you could mark migrations and your first contract as false, then only your third contract will be replaced.

See here for more info

  • OK, that seems to work, but I had to delete the .json file of the contract I was upgrading (not the whole build/ directory) before running the upgrade to avoid it getting subtly borked. – Edmund Edgar Mar 21 '18 at 2:51
  • Interesting - I thought truffle would recompile automatically and replace the .json file before running the migrations to make sure this wasn't an issue – TC8 Mar 21 '18 at 12:12
  • It seems to be somehow munging the old version and the new version together, producing function input parameter entries that aren't in either. – Edmund Edgar Mar 21 '18 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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