Search code examples
ethereumsoliditynfterc20

How to generate ERC20 coins into an NFT Marketplace when mint function is not available


Disclaimer: I'm 2 weeks into Blockchain and Blockchain Security. If I'm missing out on some basic concept, please gently point in the right direction. Thanks!

I have an NFTMarketPlace smart contract that accepts memory address of ERC20, ERC721 and AccessControlEnumerable abstract contracts in the constructor.

constructor(
    address governance,
    address erc20token,
    address nftToken
) {
    require((governance != address(0)) && (erc20token != address(0)) && (nftToken != address(0)), "NFTMarketplace: address(0)");
    ApeCoin = IERC20(erc20token);
    NFTcollection = IERC721(nftToken);
    ADMIN_ROLE = keccak256("ADMIN_ROLE");
    ADMIN_ROLE_ADMIN = keccak256("ADMIN_ROLE_ADMIN");
    _setRoleAdmin(ADMIN_ROLE, ADMIN_ROLE_ADMIN);
    _setupRole(ADMIN_ROLE_ADMIN, governance);
    _setupRole(ADMIN_ROLE, governance);
}

I used Remix IDE and deployed the 3 Abstract contracts into 3 memory address and supplied these addresses to the above constructor.

However, the totalsupply of the ERC20 is 0. And there is no mint function coded.

In this case, Is the NFTMarketplace contract supposed to work? ( As there is no currency to circulate )

enter image description here

I'm looking to mint coins, transfer it to few users, create an NFT collection and perform marketplace operations to understand the security posture in the process.


Solution

  • This answer will be helpful if you are using openzeppelin contracts.

    The ERC20 contract has internal method _mint at this location, click here

    You need to add feature of total supply and minting in your own contract, after inheriting from the ERC20 contract.

    Check out the code section below:

    contract ERC20FixedSupply is ERC20 {
      constructor() ERC20("Fixed", "FIX") {
          _mint(msg.sender, 1000);
      }
    }
    

    You can find a detailed tutorial at this link