Ethereum Asked by Unha Back on November 12, 2021
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);
};
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);
});
};
Answered by Aquila on November 12, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP