Suppose I would like to migrate 2 contracts that are dependent on each other. This can can be done with
var contract1 = artifacts.require("contract1");
var contract2 = artifacts.require("contract2");
module.exports = function(deployer) {
deployer.deploy(contract1).then(function(){
return deployer.deploy(contract2, contract1.address)
});
};
However, if I try and nest a 3rd contract that has dependencies on the first two, with the following code :
var contract1 = artifacts.require("contract1");
var contract2 = artifacts.require("contract2");
var contract3 = artifacts.require("contract3");
module.exports = function(deployer) {
deployer.deploy(contract1).then(function(){
deployer.deploy(contract1, contract2.address).then(function(){
return deployer.deploy(contract3, contract1.address, contract2.address)
})
})};
Then running truffle deploy
on this migration file only deploys the first contract and not the remaining two. What is the correct syntax for deploying 3, or even up to n contracts? Is there a nicer way than doing it than this ugly nesting?
Another question, say an additional argument else needs to be calculated for contract 3, what is the correct syntax for this? eg. I want to do something like
var contract1 = artifacts.require("contract1");
var contract2 = artifacts.require("contract2");
var contract3 = artifacts.require("contract3");
var someSol = artifacts.require("someSol.sol");
module.exports = function(deployer) {
deployer.deploy(contract1).then(function(){
deployer.deploy(contract1, contract2.address).then(function(){
const someAddress = await someSol.foo(contract1.address, contract2.address);
return deployer.deploy(contract3, contract1.address, contract2.address, someAddress)
})
})};
Any help greatly appreciated