Can't mint token using ERC20PresetMinterPauserUpgradeable

I can't mint token using ERC20PresetMinterPauserUpgradeable.

i don't understand what's going on here, I'm trying to deploy a sort of simple ICO where I have a token contract, ERC20PresetMinterPauserUpgradeable Paddy. I try to deploy it from a second contract which will be granted the role MINTER, IcoSeller.

the error I get from remix is:

call to IcoSeller.getTokenNameFromPaddy errored: Error: Internal JSON-RPC error. { "message": "VM Exception while processing transaction: revert", "code": -32000, "data": { "0x04c0f0d7e658c964b706f47d7263bb9e291fd02ada2a683259efc397bde4aac3": { "error": "revert", "program_counter": 511, "return": "0x" }, "stack": "c: VM Exception while processing transaction: revert\n at Function.c.fromResults (/Users/fabri/.nvm/versions/node/v10.24.0/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:4:192416)\n at readyCall (/Users/fabri/.nvm/versions/node/v10.24.0/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:42:50402)", "name": "c" } }

I think I'm missing something here but I can't really understand what. I am able to compile and deploy everything.

PADDY:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/presets/ERC20PresetMinterPauserUpgradeable.sol";

/**
* @title PadelCoin
* @dev it is the coin itself. here I specify the name and the simbol
* 
 */
contract Paddy is Initializable, ERC20PresetMinterPauserUpgradeable {
    
    function initializePaddy(string memory _name, string memory _symbol) public initializer{
        //create token and gives admin, minter, pauser to who deploys the contract
        ERC20PresetMinterPauserUpgradeable.initialize(_name, _symbol); 
    }
}

I can't even get the tokenName from IcoSeller contract. IcoSeller:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/presets/ERC20PresetMinterPauserUpgradeable.sol";

import "./Paddy.sol";

/**
* @dev //initializes paddy and gives this contract minter, pauser and admin role
**/
contract IcoSeller is Initializable {
    ERC20PresetMinterPauserUpgradeable paddy;

    function initializeIcoDeployer() public initializer{ 
        paddy.initialize("PaddyCoin", "PADDY"); 
    }

    /**
    * @dev emits Transfer
    **/
    function sellToPublic(address _to, uint _amount) public{
        paddy.mint(_to, _amount);
    }

   
    function getTokenNameFromPaddy() public view
     returns(string memory name){
        return paddy.name();
    }
}

here is the migration script:

const  { deployProxy,upgradeProxy } = require('@openzeppelin/truffle-upgrades');

const IcoSeller = artifacts.require('IcoSeller');

module.exports = async function (deployer) {
  const ico = await deployProxy(IcoSeller, { deployer });
  const icoUpgraded = await upgradeProxy(ico.address, IcoSeller, { deployer });
  

  console.log('Ico Deployed at address: ', ico.address);
  console.log('Ico Upgraded at address: ', icoUpgraded.address);
};

Hi, it seems like your contract is ok, I think the error is in your scripts:

const ico = await deployProxy(IcoSeller, { deployer });

Actually, upgradeable contracts do not use constructor to initialize state, so you need to call a function to initialize state, for more details, please check at: initialize functions

So I think your script should be like:

const ico = await deployProxy(IcoSeller, [], {initializer: 'initializeIcoDeployer'});

And there is tutorial, maybe you can have a look:

1 Like