Mint ERC20 Tokens with Governor example

Hello,

I was following this guide and I would like to try to mint tokens with a governance proposal and execution. The function _mint(address to, uint256 amount) function from the example ERC20 contract is however internal. Is it possible to do that?

Best,

Max

Hello,

Yes, you can set it to be public or create a public function that calls it, like:

function mint(address to, uint256 amount) public {
    _mint(to, amount);
}

But always remember to do this taking the security measures that would make sense to your project, like who is allowed to mint token and so.

Hi,

Thank you. In this case I would make the Address of the Governor Contract the only one that is allowed to execute the minting function, right?

Also I wrote a script to make a proposal, but it isn't working correctly. Could you share a script to do it the correct way?

const { CeloProvider, CeloWallet } = require("@celo-tools/celo-ethers-wrapper");
const { ethers } = require("ethers");
const myGovernorArtifact = require("../artifacts/contracts/MyGovernor.sol/MyGovernor.json");
const ERC20Artifact = require("../artifacts/contracts/GovernanceTokenERC20.sol/MyToken.json");
const contracts = require('../contracts.json');

require('dotenv').config({path: '../.env'});

(async () =>{
    const provider = new CeloProvider("https://alfajores-forno.celo-testnet.org");
    await provider.ready;

    const deployer = new CeloWallet(String(process.env.PRIVATE_KEY_DEPLOYER), provider);
    const proposer = new CeloWallet(String(process.env.PRIVATE_KEY_PROPOSER), provider);
    const mintAmount = ethers.utils.parseEther("1"); 

  
    const erc20GovToken = new ethers.Contract(contracts.governanceTokenERC20, ERC20Artifact.abi, deployer);
    const transferCalldata = erc20GovToken.interface.encodeFunctionData("mint", [proposer.address, mintAmount]);


    const governor = new ethers.Contract(contracts.myGovernor, myGovernorArtifact.abi, proposer);
    await governor.propose(
        [contracts.governanceTokenERC20],
        [0],
        [transferCalldata],
        "Proposal #1: Mint 1 token to proposer",
    );

})().catch((error) => {
    console.error(error);
    process.exitCode = 1;
});

Thanks

For the first question, I suggest to set roles. And for the second questions please include what is exactly failing?