ERC20PresetMinterPauser: how to verify on Etherscan and is it safe to use in a Crowdsale?

Hello

I am trying to create a “crowdsale token”, for the token I am using ERC20PresetMinterPauser The IDE I am using is Remix, the contract compiles, I managed to deploy it in the “ropsten” network, but now in the step of “verify and publish “I can’t find the” Contract ByteCode and ABI "that it asks me to do so. The question is, in Remix where can I find the “Contract ByteCode and ABI” for the contract “ERC20PresetMinterPauser”?

Another question, for the “crowdsale” there is no problem if I use ERC20PresetMinterPauser"?

1 Like

Hi @jeissoni,

Welcome to the community :wave:

I encourage you to go through: Points to consider when creating a fungible token (ERC20, ERC777)

Part of this is appropriately testing your solution, so you may want to use Truffle or Hardhat for this.

Please note, Crowdsales are in OpenZeppelin Contracts 2.x https://docs.openzeppelin.com/contracts/2.x/crowdsales whilst the Preset contract is in OpenZeppelin Contracts 3.x https://docs.openzeppelin.com/contracts/3.x/erc20#Presets
So you may want to deploy your token separately e.g. from a separate project.

Regards verifying, I recommend the following: Verify smart contract inheriting from OpenZeppelin Contracts

If you have issues you can share your Solidity code, and the parameters passed to the constructor and whether optimization was enabled and I can try to help.

From: https://docs.openzeppelin.com/contracts/3.x/erc20#Presets
This contract is ready to deploy without having to write any Solidity code. It can be used as-is for quick prototyping and testing, but is also suitable for production environments.

1 Like

Hi @abcoathup thanks for your reply. As a newbie I have many doubts, one of them is: How can I link the token contract with the sale contract? The idea is that the sales contract is the one who mints the coins. If I do it as you suggest, for separate projects, how can I associate the token contract with the sale one? Again, thank you very much.

1 Like

Hi @jeissoni,

In the constructor of the Crowdsale you pass in the address of the token that you create.

This means you should deploy your token first, provide the token address to the crowdsale when you deploy the crowdsale.

Finally you should give the minter role to the crowdsale.

You should also write tests to check this.

Hi @abcoathup

How can I deliver the role of minter to the sale contract, in the token contract? What I see is that the role is granted is in the constructor of the token contract, so how can I grant the role after the token contract is deployed?

pragma solidity ^0.6.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/AccessControl.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/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") {
        // Grant the contract deployer the default admin role: it will be able
        // to grant and revoke any roles
        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _setupRole(MINTER_ROLE, msg.sender);//How can I do this after the contract is displayed?
        _setupRole(MINTER_ROLE, 0xAb8483F64d9C.................);  // How can I do this after the contract is displayed?
    }

    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);
    }
}
1 Like

Hi @jeissoni,

The deployer of the contract in this example has the DEFAULT_ADMIN_ROLE.

After deploying you can call grantRole to the sale contract.
See the documentation for details on granting roles:

1 Like