2

There 2 contracts: Token and Crowdsale. To deploy crowdsale contract we have to know address of Token contract. How to get this address in migrations?

var Migrations = artifacts.require("./Migrations.sol");
var ERC20Token = artifacts.require("./ERC20Token.sol");
var ERC20Crowdsale = artifacts.require("./ERC20Crowdsale.sol");

module.exports = function(deployer, accounts) {
  deployer.deploy(Migrations);
  deployer.deploy(ERC20Token, 1000, "Test Coin", "TCT");
  deployer.deploy(ERC20Crowdsale, THERE SHOULD BE TOKEN ADDRESS);
}

Thanks!

2

Truffle dependency documentation

module.exports = function(deployer, accounts) {
  deployer.deploy(Migrations);
  deployer.deploy(ERC20Token, 1000, "Test Coin", "TCT").then(() => {
    return deployer.deploy(ERC20Crowdsale, ERC20Token.address);
  });
};

Note - You should put your migrations into a different file than 1_initial_migration.js. It will cause problems when you redeploy. Leave Migrations in 1_initial_migration.js and put your deployments in 2_deploy_contracts.js (the filename can be anything as long as it starts with "2_"). From the Truffle migration file documentation:

Note that the filename is prefixed with a number and is suffixed by a description. The numbered prefix is required in order to record whether the migration ran successfully. The suffix is purely for human readability and comprehension.

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.