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);
};