Hi
I have the following case. Create an ERC20 mint token with the following code.
pragma solidity ^0.6.5;
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20, AccessControl {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
constructor() public ERC20("MyToken", "TKN") {
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
}
function mint(address to, uint256 amount) public {
require(hasRole(MINTER_ROLE, msg.sender), "Caller is not a minter");
_mint(to, amount);
}
function burn(address from, uint256 amount) public {
require(hasRole(BURNER_ROLE, msg.sender), "Caller is not a burner");
_burn(from, amount);
}
}
Address that takes me in testnet is: 0x7823549A14ab83d50B6654336A42Bb679A695875
Then create a sales contract with the following code:
pragma solidity ^0.5.0;
import "@openzeppelin/contracts/crowdsale/Crowdsale.sol";
import "@openzeppelin/contracts/crowdsale/emission/MintedCrowdsale.sol";
import "@openzeppelin/contracts/crowdsale/validation/CappedCrowdsale.sol";
import "@openzeppelin/contracts/crowdsale/validation/TimedCrowdsale.sol";
import "@openzeppelin/contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol";
import "@openzeppelin/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol";
contract DappTokenCrowdsale is Crowdsale, MintedCrowdsale, CappedCrowdsale, TimedCrowdsale, PostDeliveryCrowdsale, IncreasingPriceCrowdsale {
mapping(address => uint256) public contributions;
constructor(
uint256 _rate,
address payable _wallet,
uint256 _cap,
uint256 _openingTime,
uint256 _closingTime,
uint256 _initialRate,
uint256 _finaleRate,
IERC20 _token
)
Crowdsale(_rate, _wallet, _token)
CappedCrowdsale(_cap)
TimedCrowdsale(_openingTime, _closingTime)
PostDeliveryCrowdsale()
IncreasingPriceCrowdsale (_initialRate, _finaleRate)
public
{
}
function getUserContribution(address _beneficiary)
public view returns (uint256)
{
return contributions[_beneficiary];
}
}
The parameters I use are the following:
const DappTokenCrowdsale = artifacts.require("DappTokenCrowdsale");
let rate = 400;
let wallet = "0x56679A0bD8a24007aD5cBBd4375179c3A81C9319";
let cap = 50000000000000000000n;
let openTime = 1605207911; // //Epoch Unix Time Stamp
let closeTime = 1605218711; // //Epoch Unix Time Stamp
let initialRate = 400;
let finalRate = 50;
let toke = "0x7823549A14ab83d50B6654336A42Bb679A695875";
module.exports = function(_deployer) {
_deployer.deploy(DappTokenCrowdsale, rate, wallet, cap, openTime, closeTime, initialRate, finalRate, toke);
};
Then in the token contract I gave it MINTER_ROLE permissions from the grantRole function so that it can token the sale contract.
Now when I want to test, I know that the sale is open, I try to send 1 ETH to the sale contract from metamak, it generates an error.
Is there anything else I need to do? Could you give me any suggestions please.