0

I deployed Token and Crowdsale contract in separate migration files. During Migration, there was no error. Migration logs are share:

Running migration: 2_deploy_token.js Deploying DappToken... ... 0xc1ed596e0249507186d75f2d42ba1c34e5b72697774baf9a283e0fb422214b70 DappToken: 0x949e24c24a79f437bbf75d3da7b9ba50235c2a8a Saving successful migration to network... ... 0x1c8bc4b87bfbfa40bb16aa3eb6cf0341efc79f444b1e293abd1f0db394881d55 Saving artifacts... Running migration: 3_deploy_crowdsale.js Saving successful migration to network... Deploying DappTokenCrowdsale... ... 0xdae8535756b9b7100af8d1a3bdf9d20b622c25dcb03aa40435b7f7019bfcdf7a Saving artifacts...

After this, when I tried to create an instance of Crowdsale using truffle console as

truffle(ganache)> DappTokenCrowdsale.deployed().then(ic => tokensale = ic)

I got the error:

Error: DappTokenCrowdsale has not been deployed to detected network (network/artifact mismatch)

Although i have successfully created the instance of DappToken contract. Related files are shared below:

DappTokenCrowdsale.sol

pragma solidity 0.4.24;

import "openzeppelin-solidity/contracts/crowdsale/Crowdsale.sol";

contract DappTokenCrowdsale is Crowdsale {

  constructor(
    uint256 _rate,
    address _wallet,
    ERC20 _token
  )
    Crowdsale(_rate, _wallet, _token)
    public
  {
  }
}

3_deploy_crowdsale.js

const DappToken = artifacts.require("./DappToken.sol");
const DappTokenCrowdsale = artifacts.require('DappTokenCrowdsale');

module.exports = async function(deployer, network, accounts) {
    const deployedToken = await DappToken.deployed();
    const _rate = 1000;
    const _wallet = accounts[1];
    const _token = deployedToken.address;

    await deployer.deploy(DappTokenCrowdsale, _rate, _wallet, _token);
};

2_deploy_token.js

const DappToken = artifacts.require("./DappToken.sol");

module.exports = async function(deployer, network, accounts) {
  const _name = "Dapp Token";
  const _symbol = "DAPP";
  const _decimals = 18;

  await deployer.deploy(DappToken, _name, _symbol, _decimals);
};
  • The migration message was like: – Unha Back Nov 17 '18 at 12:57
  • Running migration: 2_deploy_token.js Deploying DappToken... ... 0xc1ed596e0249507186d75f2d42ba1c34e5b72697774baf9a283e0fb422214b70 DappToken: 0x949e24c24a79f437bbf75d3da7b9ba50235c2a8a Saving successful migration to network... ... 0x1c8bc4b87bfbfa40bb16aa3eb6cf0341efc79f444b1e293abd1f0db394881d55 Saving artifacts... Running migration: 3_deploy_crowdsale.js Saving successful migration to network... Deploying DappTokenCrowdsale... ... 0xdae8535756b9b7100af8d1a3bdf9d20b622c25dcb03aa40435b7f7019bfcdf7a Saving artifacts... – Unha Back Nov 17 '18 at 12:59
  • Your question seems a bit confusing. So at which step and in which file you got the error? – Aniket Nov 17 '18 at 13:07
  • Hi @A.K. um, when I run migration commend, it looks all contracts(DappToken, DappTokenCrowdsale) were deployed. However, when I accessed truffle console, and tried to create an instance of those contracts, I cannot create for crowdsale. the message said, DappTokenCrowdsale has not been deployed even though there were no errors on the migration processing. – Unha Back Nov 17 '18 at 13:15
  • If you have questions on using OpenZeppelin you can also ask in the Community Forum: forum.openzeppelin.com Disclosure: I am the Community Manager at OpenZeppelin – abcoathup Nov 4 at 7:24
0

In case of migration you can't know for sure that the contract deployed, it returns transaction hash. You need to remove async/await(it is the simplest way) in order to see deployment result.

const DappToken = artifacts.require("./DappToken.sol");

module.exports = function(deployer, network, accounts) {
    const _name = "Dapp Token";
    const _symbol = "DAPP";
    const _decimals = 18;

    deployer.deploy(DappToken, _name, _symbol, _decimals)
        .then(function () {
             return deployer.deploy(Crowdsale, DappToken.address);
        });
};
  • Thanks for comment. I want to migrate Token and Crowdsale separately, and in deploy_crowdsale.js, how can I get the token address has been already deployed? I tried const deployedToken = DappToken.deployed(), but it is undefined.. – Unha Back Nov 17 '18 at 22:10
  • @UnhaBack take a look on code above – Aquila Nov 17 '18 at 22:21
  • Thanks @Aquila. Just curious. If I want to separate the migration file for Token and Crowdsale individually, is there any way to get the token address in Crowdsale migration file? – Unha Back Nov 17 '18 at 22:30
  • @UnhaBack yes, it is possible, there multiple ways to do this. for instance you can take a look github.com/oceanprotocol/keeper-contracts migration script for OceanToken – Aquila Nov 17 '18 at 23:26
  • Thanks @Aqualia. I found the problem. Actually, I got the instance from the definition of DappToken on the top, but I defined again as "const deployedToken = DappToken.deployed()" it made error. Now, it is working well. – Unha Back Nov 18 '18 at 10:27

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.