pragma solidity >=0.4.22 <0.8.0;
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import '@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol';
import '@openzeppelin/contracts/token/ERC20/ERC20Pausable.sol';
contract TokenGRAV is ERC20, ERC20Detailed, ERC20Pausable {
address public admin;
constructor(
uint256 initialSupply
) ERC20Detailed("Gravitation", "GRA", 18) public{
admin = msg.sender;
_mint(msg.sender, initialSupply);
}
function updateAdmin(address newAdmin) external {
require(msg.sender == admin, 'admin');
admin = newAdmin;
}
}
Crowdsale
pragma solidity >=0.4.22 <0.8.0;
import '@openzeppelin/contracts/crowdsale/Crowdsale.sol';
import '@openzeppelin/contracts/crowdsale/validation/CappedCrowdsale.sol';
import '@openzeppelin/contracts/crowdsale/validation/TimedCrowdsale.sol';
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '../contracts/TokenGRAV.sol';
contract ICO is Crowdsale, CappedCrowdsale, TimedCrowdsale {
address public admin;
constructor(
uint256 openingTime, // opening time in unix epoch seconds
uint256 closingTime, // closing time in unix epoch seconds
uint256 rate,
address payable wallet, // wallet to send Ether
IERC20 token, // the token
uint256 cap // total cap, in wei
)
CappedCrowdsale(cap)
TimedCrowdsale(openingTime, closingTime)
Crowdsale(rate, wallet, token)
public
{
admin = msg.sender;
// nice, we just created a crowdsale that's only open
// for a certain amount of time
// and stops accepting contributions once it reaches `cap`
}
modifier onlyAdmin() {
require(msg.sender == admin, 'admin');
_;
}
}
deploy js
const TokenGRAV = artifacts.require("../TokenGRAV");
const ICO = artifacts.require('../ICO');
module.exports = async function (deployer) {
const initialSupply = web3.utils.toWei('10000', 'ether'); // 10 m
const openingTime = 1606660200;
const closingTime = 1606694400;
const wallet = '0x72c5AEa64e256df193dCf241bC532339BEbB0235';
const rate = '1000000000000000000'; //5000000000000000000000000000000000
const cap = web3.utils.toWei('5000', 'ether');
//Token
await deployer.deploy(
TokenGRAV,
initialSupply
);
const token = await TokenGRAV.deployed();
// ICO
await deployer.deploy(
ICO,
openingTime,
closingTime,
rate,
wallet,
token.address,
cap
);
const ico = await ICO.deployed();
await token.updateAdmin(ico.address);
};
test show
1) Crowdsale
with token
"before each" hook for "requires a non-zero rate":
Error: Invalid number of parameters for "undefined". Got 0 expected 1!
at PromiEvent (node_modules/@truffle/contract/lib/promievent.js:9:30)
at /home/asven/projects/icoProgect/node_modules/@truffle/contract/lib/execute.js:223:26
at Function.new (node_modules/@truffle/contract/lib/contract/constructorMethods.js:57:53)
at Context.<anonymous> (test/test.js:36:41)
at processImmediate (internal/timers.js:456:21)
it migrate to ganache but crowdsale not send tokens