-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Migrating multiple contracts where a subsequent contract is deployed in a .then clause or after an await results in only first contract being deployed #650
Comments
You need to return
or
|
I will give it a try and report back (probably in a couple days when I can return to my project). |
This is still an issue in 4.0.1 only .then and Promise chaining seems to work |
Tried every possible combination, async + await, then() and async+await+then(), it doesn't work. In fact it always save Artifacts before deploying second contract, that's why you do not see address of the second contract. In my case I see address of the second contract after saving artifacts: So if I run I get: But if I check address "0xad89528ffe22aa057cfbec6c9ccf2367a638eb79" I see that contract is there: |
This issue seems to be a duplicate of #501. |
@ismaelbej Thank you for noting this, closing here in favor of #501.. @dzentota @mhchu |
@dzentota Could you share the code from your migrations that's not working? |
Hi, unfortunately I don't have all the variants I've tried. Here is an example with var Crowdsale = artifacts.require("./Crowdsale.sol");
var SampleCampaign = artifacts.require('./SampleCampaign.sol');
module.exports = function (deployer) {
Crowdsale.deployed().then(function (_) {
console.log(Crowdsale.address);
return _.token.call();
}).then(function(tokenAddress) {
let crowdsaleAddress = Crowdsale.address;
let minContribution = 1000000000000000000;
let maxContribution = 10000000000000000000;
let softCap = 5000000000000000000;
let hardCap = 100000000000000000000;
let startTime = Math.floor(Date.now() / 1000);
let endTime = Math.floor(Date.now() / 1000) + 100000;
let fee = 1;
let bountyFee = 1;
deployer.deploy(
SampleCampaign,
crowdsaleAddress,
tokenAddress,
minContribution,
maxContribution,
softCap,
hardCap,
startTime,
endTime,
fee,
bountyFee
);
})
} Output:
Actually, I see all this text except |
@dzentota The example @Velenir gives in this issue above is the model you should follow. If you want to run async logic in the migrations you must return it as a promise to the module.exports = function (deployer) {
deployer.then( function() {
return Crowdsale.deployed() .... etc ...
); Additionally make sure you return everything async in the promise chain. For example the |
Thanks @cgewecke now it works!!! |
@dzentota @cgewecke yes, this part is key in a way I can't quite understand yet. Is this because the main deployment function "knows to wait" for the promise chain to finish executing when it depends on its return value? Is the value returned from the deployment function actually used by truffle in any way...? |
Issue
When migrating more than one contract the following works:
but if the second contract needs information from the first contract to be deployed, then this:
does not work. Only contractA is deployed to the network and
truffle migrate
ends after showing contractB's address and does not say "Saving successful migration to network..."This is true even in the simplified example of:
The use of .then() or deployer.then() results in the same behavior - only the first contract is saved to the network.
In all cases,
truffle migrate
saysDeploying contractB
and providescontractB: <contractB address>
but it does not saySaving successful migration to network...
Steps to Reproduce
Running truffle 3.4.11, node 7.10.1, and TestRPC 4.1.3 and simple contractA in contracts/contractA.sol and contractB in contracts/contractB.sol with migrations/2_deploy_contracts.js containing:
contractA will be deployed on the network while contractB will not. (Obviously, this is not the use case, this is the simplest replication. The use case would be something closer to:
Expected Behavior
Both contracts should be on the network.
Actual Results
truffle network
shows only the first contract. Usingtruffle console
and trying to accesscontractB.deployed()
results in a message that the contract is not deployed on the network.The text was updated successfully, but these errors were encountered: