2

I have created a ProductFactory contract which creates instances of another Product contract. Now I change code in the Product contract which is imported into the ProductFactory and run

truffle migrate

When I create a new Product instance using ProductFactory the new Product does not reflect changes (new methods, new variables) in the Product contract. The migration file only deploys the ProductFactory like below:

 var ProductFactory = artifacts.require("./ProductFactory.sol");
    module.exports = function(deployer) {
      deployer.deploy(ProductFactory, {gas:4555000});
    };

What should I do to get the Product contract code updated? Do I need to deploy the Product contract also separately?

2 Answers 2

3

you have to re-deploy the modified version of your contract after each change. You can do that by using the --reset flag with your migrate/deploy command, e.g. truffle migrate --reset

0

This is how it worked. I was modifying the Product contract but not the ProductFactory which referenced the Product. I had not deployed the Product Contract separately. And the truffle migration does not redeploy only the dependency in such a case. (I guess thats how solidity is) As a workaround I added a variable like below to ProductFactory

uint256 public version = 10;

Now everytime I make a change to Product I increment this value in ProductFactory and the changes are updated and redployed.

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.