7

Probably this is not possible, but I still have to ask.

Let me follow the example created in truffle init. It contains a contract called MetaCoin.sol. Say,

  1. I have deployed it on the network (the first version of it).
  2. Then I have extended it with a foo() method.
  3. Now I want to deploy a new modified version of the contract with the same name MetaCoin but the new code of it. Is there a way of doing it?

As the hint there is a contract called Migrations.sol which has a method called upgrade():

function upgrade(address new_address) restricted { Migrations upgraded = Migrations(new_address); upgraded.setCompleted(last_completed_migration); }

that sets a new address for the code of the contract. Is there a better way of doing versioning or upgrades (deploy rollouts) of the coins code?

  • Probably the way to answer it is written here by calling new() as in ..You can use this method to deploy a completely new instance of a contract onto the network. Maybe I simply misunderstand the whole instances thing. – Yauhen Yakimovich May 28 '17 at 20:55
  • Adding alternative link to migrations in truffle. – Yauhen Yakimovich Jul 17 '17 at 15:25
12

you should use truffle(.cmd) migrate --reset to redeploy it on the network.
everytime you run migrate an new address and new contract is created.

(sorry reputatio too low to comment)

| improve this answer | |
  • 1
    I've upvoted this answer to give you +10 rep. – Badr Bellaj Jul 14 '17 at 15:02
  • 1
    reset sounds like the wrong name :/ but I think it's the way to go. What if I have 10 contracts and I only changed 1, would reset deploy 10 of them or the one changed? – EralpB Sep 1 '17 at 8:29
  • marking as an answer as it seems a correct one after some time of working with truffle framework. I would in general recommend another security framework called openzeppelin.org – Yauhen Yakimovich Dec 27 '17 at 9:29
2

Since google lists this question pretty far on top by searching for "truffle deploy new contract" and accepted answer does redeploy all(!) contracts I post following solution for redeploying a single contract:

You need to use both flags --f NUMBER and --to NUMBER with the command "truffle migrate" (look here)

Example, for redeploying a contract with the migration file "5_mycontract_migration.js":

truffle migrate --f 5 --to 5
| improve this answer | |
1

To redeploy a single contract MyContract:

  • create a new migration with truffle create migration my_new_migration_name
  • in the new migration file (found in the migrations folder), you can redeploy using deployer.deploy(MyContract)

You can also use the truffle deploy "force" feature: truffle deploy -f migration_name reruns a specific migration

| improve this answer | |

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.