Solidity

部署 Crowdsale.sol - 錯誤

  • December 5, 2020

為了能夠購買 MyToken,我應該在哪裡將 RATE(token/ETH)(例如來自Openzeppelin docs on crowdsales的以下程式碼)包含到我的 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())
};

您應該將它包含在deploy_contract.js中,因為您已經在此處進行了操作:

await deployer.deploy(SimpleCrowdsale, 1, accounts[0], token.address);

參數1是您提供的 RATE。

引用自:https://ethereum.stackexchange.com/questions/90774