...by Daniel Szego
"Simplicity is the ultimate sophistication."
Leonardo da Vinci

Wednesday, December 6, 2017

Solidity and Truffle Tips and Tricks - migrating contracts with dependencies

Whenever you have to deploy several contracts in a way that they have dependencies with each others, like the constructor of one contract requires the address of one or two contracts that should be developed previously, the following pattern can be used. It really works :)
var a, b;
deployer.then(function() {
  // Create a new version of A
  return A.new();
}).then(function(instance) {
  a = instance;
  // Get the deployed instance of B
  return B.deployed():
}).then(function(instance) {
  b = instance;
  // Set the new instance of A's address on B via B's setA() function.
  return b.setA(a.address);