Truffle Deployment – Returning Token Contract Address on Truffle Deploy

addressescontract-deploymentsoliditytruffletruffle-migration

I am trying to figure out how to return the address of a contract when I deploy it with truffle's deployer.deploy. So the goal is that when I deploy a contract that is a custom token, I want to return that address once it's deployed and pass that address to my CrowdSale contract constructor. I am getting undefined for the instance of the deployed contract when doing this like so:

1_initial_migration.js

module.exports = function(deployer) {
  deployer.deploy(Migrations);
  deployer.deploy(CrowdTestToken).then((instance) => {
    console.log(instance);
    deployer.deploy(CrowdSale, instance.address);
  });
};

In the above example, instance is undefined. Does anybody know how I can get the address of the CrowdTestToken contract in the deployment script?

Best Answer

The address of the contract is just the variable name of the deployed contract. Try this:

deployer.deploy(CrowdTestToken).then(function(){
    return deployer.deploy(CrowdSale, CrowdTestToken.address)});
Related Topic