To expand on the question, I have created an erc20 token contract, & a crowdsale contract. For each file, I intend to create separate migration files.

How can i get the token address for reference in the crowdsale contract?

Thank you

Sidenote: I am aware of the general approach, most contracts have a single migration file, say deploy.js. In which, crowdsale contract inherits the token address through a promise.

3 Answers 3


Truffle has functionality deployed() which, if I remember right, gets the contract deployed during migrations. Documentation on that is a bit flimsy: https://www.trufflesuite.com/docs/truffle/getting-started/interacting-with-your-contracts

So you can get the instance with deployed() and use its address in the next migration file.


I had the same issue and I solved it by using a .env file on my root directory.

I used the npm package dotenv to fetch the variables. They are available throughout the application.


Here is how it worked out.

In the crowdsale migration.js, I've deployed token contract first, fetched the address through async. Assigned it to a const. This const thereafter acted as a pointer to the token contract.

Migration code below

const Crowdsale = artifacts.require("contracts/Crowdsale.sol");
const Token = artifacts.require("contracts/Token.sol");

module.exports = async function(deployer, network, accounts)  {
  const deployedNetwork = await Token.deployed();
  const _rate = 100;
  const _tokenAvailable = 1000;
  const _token = deployedNetwork.address;
  const _wallet = accounts[6];

  return deployer.deploy(Crowdsale, _rate, _wallet, _token, _tokenAvailable); 


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.