为了能够购买MyToken,我在哪里包括费率(令牌/ETH),如下面的代码从大众销售的Openzeppelin文档到我的deploy_contract.js或MyToken.sol?以及如何插入它?
new Crowdsale(
1, // rate in TKNbits
WALLET, // address where Ether is sent
TOKEN // the token contract address
);下面是来自Openzeppelin的Simpletoken、Crowdsale和部署合同:
/ contracts/SimpleToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.5.5;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
contract SimpleToken is Context, ERC20, ERC20Detailed {
constructor(
string memory name,
string memory symbol,
uint256 initialSupply
) public ERC20Detailed(name, symbol, 18) {
_mint(_msgSender(), initialSupply);
}
}
// contracts/SimpleCrowdsale.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.5.5;
import "@openzeppelin/contracts/crowdsale/Crowdsale.sol";
contract SimpleCrowdsale is Crowdsale {
constructor(
uint256 rate,
address payable wallet,
IERC20 token
) public Crowdsale(rate, wallet, token) {}
}
// migrations/2_deploy.js
// SPDX-License-Identifier: MIT
const SimpleToken = artifacts.require("SimpleToken");
const SimpleCrowdsale = artifacts.require("SimpleCrowdsale");
module.exports = async function (deployer, network, accounts) {
await deployer.deploy(SimpleToken, 'Simple Token', 'SIM', '10000000000000000000000');
const token = await SimpleToken.deployed();
await deployer.deploy(SimpleCrowdsale, 1, accounts[0], token.address);
const crowdsale = await SimpleCrowdsale.deployed();
token.transfer(crowdsale.address, await token.totalSupply())
};发布于 2020-12-05 10:13:10
您应该将其包含在deploy_contract.js中,因为您已经在这里这样做了:
await deployer.deploy(SimpleCrowdsale, 1, accounts[0], token.address);论点1是您所提供的速率。
https://ethereum.stackexchange.com/questions/90774
复制相似问题