Mint new erc20 contract from openzepplin wizard with remix and metamask

I have created a new erc20 token using the openzepplin wizard

Here is the code https://github.com/braincargo/BrainCoin/blob/main/BrainCoin.sol

When I deploy the contract using remix, none of the function return the expected results
owner is address: 0x0000000000000000000000000000000000000000"
symbol is an empty string
name is an empty string
total supply is 0

And here is the deployment etherscan.io/address/0x5aae026d0d9f261903f803994d406ecf3c5162f8

Any idea what I did wrong and how to fix it so everything works: owner, supply, name symbol etc?

What did your deployment look like, and how do you determine that "none of the function return the expected results"?

Welcome to Remix 0.31.1

Your files are stored in indexedDB, 192.11 KB / 10 GB used

You can use this terminal to:

  • Check transactions details and start debugging.
  • Execute JavaScript scripts:
    - Input a script directly in the command line interface
    - Select a Javascript file in the file explorer and then run remix.execute() or remix.exeCurrent() in the command line interface
    - Right click on a JavaScript file in the file explorer and then click Run

The following libraries are accessible:

  • [web3 version 1.5.2]
  • [ethers.js]
  • remix

Type the library name to see available commands.

creation of BrainCoin pending...

view on etherscan

[block:16746029 txIndex:48]

from: 0x85D...E740c

to: BrainCoin.(constructor)

value: 0 wei

data: 0x60a...20033

logs: 1

hash: 0xd8c...b5e1d

status true Transaction mined and execution succeed
transaction hash 0x6429ab104a9a26d31711e76791133c7eab97574dfbc197722a863a929ec878cb
from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.(constructor)
gas 5236482 gas
transaction cost 5236482 gas
input 0x60a...20033
decoded input {}
decoded output -
logs [ { "from": "0x5AaE026D0D9F261903f803994d406ECF3c5162F8", "topic": "0x7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498", "event": "Initialized", "args": { "0": 255, "version": 255 } } ]
val 0 wei

call to BrainCoin.name

call [call]

from: 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c

to: BrainCoin.name()

data: 0x06f...dde03

from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.name() 0x5AaE026D0D9F261903f803994d406ECF3c5162F8
input 0x06f...dde03
decoded input {}
decoded output { "0": "string: " }
logs

call to BrainCoin.owner

call [call]

from: 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c

to: BrainCoin.owner()

data: 0x8da...5cb5b

from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.owner() 0x5AaE026D0D9F261903f803994d406ECF3c5162F8
input 0x8da...5cb5b
decoded input {}
decoded output { "0": "address: 0x0000000000000000000000000000000000000000" }
logs

call to BrainCoin.symbol

call [call]

from: 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c

to: BrainCoin.symbol()

data: 0x95d...89b41

from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.symbol() 0x5AaE026D0D9F261903f803994d406ECF3c5162F8
input 0x95d...89b41
decoded input {}
decoded output { "0": "string: " }
logs

call to BrainCoin.totalSupply

call [call]

from: 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c

to: BrainCoin.totalSupply()

data: 0x181...60ddd

from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.totalSupply() 0x5AaE026D0D9F261903f803994d406ECF3c5162F8
input 0x181...60ddd
decoded input {}
decoded output { "0": "uint256: 0" }
logs

transact to BrainCoin.initialize pending ...

transact to BrainCoin.initialize errored: Returned error: {"jsonrpc":"2.0","error":"execution reverted: Initializable: contract is already initialized","id":4367685579365356}

call to BrainCoin.balanceOf

call [call]

from: 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c

to: BrainCoin.balanceOf(address)

data: 0x70a...e740c

from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.balanceOf(address) 0x5AaE026D0D9F261903f803994d406ECF3c5162F8
input 0x70a...e740c
decoded input { "address account": "0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c" }
decoded output { "0": "uint256: 0" }
logs

call to BrainCoin.decimals

call [call]

from: 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c

to: BrainCoin.decimals()

data: 0x313...ce567

from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.decimals() 0x5AaE026D0D9F261903f803994d406ECF3c5162F8
input 0x313...ce567
decoded input {}
decoded output { "0": "uint8: 18" }
logs

call to BrainCoin.name

call [call]

from: 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c

to: BrainCoin.name()

data: 0x06f...dde03

from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.name() 0x5AaE026D0D9F261903f803994d406ECF3c5162F8
input 0x06f...dde03
decoded input {}
decoded output { "0": "string: " }
logs

Welcome to Remix 0.31.1

Your files are stored in indexedDB, 192.11 KB / 10 GB used

You can use this terminal to:

  • Check transactions details and start debugging.
  • Execute JavaScript scripts:
    - Input a script directly in the command line interface
    - Select a Javascript file in the file explorer and then run remix.execute() or remix.exeCurrent() in the command line interface
    - Right click on a JavaScript file in the file explorer and then click Run

The following libraries are accessible:

  • [web3 version 1.5.2]
  • [ethers.js]
  • remix

Type the library name to see available commands.

creation of BrainCoin pending...

view on etherscan

[block:16746029 txIndex:48]

from: 0x85D...E740c

to: BrainCoin.(constructor)

value: 0 wei

data: 0x60a...20033

logs: 1

hash: 0xd8c...b5e1d

status true Transaction mined and execution succeed
transaction hash 0x6429ab104a9a26d31711e76791133c7eab97574dfbc197722a863a929ec878cb
from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.(constructor)
gas 5236482 gas
transaction cost 5236482 gas
input 0x60a...20033
decoded input {}
decoded output -
logs [ { "from": "0x5AaE026D0D9F261903f803994d406ECF3c5162F8", "topic": "0x7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498", "event": "Initialized", "args": { "0": 255, "version": 255 } } ]
val 0 wei

call to BrainCoin.name

call [call]

from: 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c

to: BrainCoin.name()

data: 0x06f...dde03

from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.name() 0x5AaE026D0D9F261903f803994d406ECF3c5162F8
input 0x06f...dde03
decoded input {}
decoded output { "0": "string: " }
logs

call to BrainCoin.owner

call [call]

from: 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c

to: BrainCoin.owner()

data: 0x8da...5cb5b

from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.owner() 0x5AaE026D0D9F261903f803994d406ECF3c5162F8
input 0x8da...5cb5b
decoded input {}
decoded output { "0": "address: 0x0000000000000000000000000000000000000000" }
logs

call to BrainCoin.symbol

call [call]

from: 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c

to: BrainCoin.symbol()

data: 0x95d...89b41

from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.symbol() 0x5AaE026D0D9F261903f803994d406ECF3c5162F8
input 0x95d...89b41
decoded input {}
decoded output { "0": "string: " }
logs

call to BrainCoin.totalSupply

call [call]

from: 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c

to: BrainCoin.totalSupply()

data: 0x181...60ddd

from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.totalSupply() 0x5AaE026D0D9F261903f803994d406ECF3c5162F8
input 0x181...60ddd
decoded input {}
decoded output { "0": "uint256: 0" }
logs

call to BrainCoin.decimals

call [call]

from: 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c

to: BrainCoin.decimals()

data: 0x313...ce567

from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.decimals() 0x5AaE026D0D9F261903f803994d406ECF3c5162F8
input 0x313...ce567
decoded input {}
decoded output { "0": "uint8: 18" }
logs

call to BrainCoin.balanceOf

call [call]

from: 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c

to: BrainCoin.balanceOf(address)

data: 0x70a...e740c

from 0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c
to BrainCoin.balanceOf(address) 0x5AaE026D0D9F261903f803994d406ECF3c5162F8
input 0x70a...e740c
decoded input { "address account": "0x85D6D0c9E22DaEDe8e3f5BA2eE2ad11B92FE740c" }
decoded output { "0": "uint256: 0" }
logs

I fixed it, it was because it was an upgradeable erc20 token, which you cannot deploy with remix.
Any idea how I can deploy an upgradeable erc20 token?
The documentation does not make it clear.

Well, I'm not sure about Remix, but with Truffle, for example, you can do something like this:

const ERC20 = artifacts.require("ERC20");
const Proxy = artifacts.require("TransparentUpgradeableProxy");

const hash = web3.utils.keccak256("initialize()");

let proxy;

async function newToken(name, symbol, deployer, upgrader) {
    const logic = await ERC20.new(name, symbol, {from: deployer});
    if (proxy === undefined) {
        proxy = await Proxy.new(logic.address, upgrader, hash, {from: deployer});
    }
    else {
        await proxy.upgradeTo(logic.address, {from: upgrader});
    }
}

The code in your original post does not look like an upgradeable contract.

You can use Upgrades plugins for Hardhat or Truffle to deploy upgradeable contracts. See https://docs.openzeppelin.com/upgrades-plugins/1.x/

Or you can use Remix if you use the UUPS proxy pattern. See https://remix-ide.readthedocs.io/en/latest/run_proxy_contracts.html

Thank you for those links, this is the original code with the upgradeable contract

When I fixed it, I pushed the new version. I am going to try the upgradeable contracts this weekend.

I have added my proxy code here in the dev branch

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

const Box = artifacts.require('BrainCoin');
const BoxV2 = artifacts.require('BrainCoinV2');

module.exports = async function (deployer) {
  const instance = await deployProxy(Box, [42], { deployer });
  console.log("instance", instance.address);
  const upgraded = await upgradeProxy(instance.address, BoxV2, { deployer });
  console.log("Upgraded", upgraded.address);
}

However, when I try to run truffle migrate I get the following error

Error: Invalid number of parameters for "initialize". Got 1 expected 0!
    at Object.InvalidNumberOfParams (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-core-helpers/lib/errors.js:33:1)
    at Object._createTxObject (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-contract/lib/index.js:695:1)
    at getInitializerData (/node_modules/@openzeppelin/truffle-upgrades/src/utils/initializer-data.ts:13:46)
    at deployProxy (/node_modules/@openzeppelin/truffle-upgrades/src/deploy-proxy.ts:37:34)
    at module.exports (/migrations/1_deploy_contracts.js:7:20)

Your initialize function takes 0 input parameters:

function initialize() initializer public {
    ...
}

But with [42], you are attempting to pass to it 1 input parameter.

Jumping in, I realised that the code that you deployed is probably not what you wanted to deploy:

  • The constructor did not mint, has it should have
  • The contract returns 18 when calling decimals, but nothing on name and symbol like if it the storage was not setup correctly
  • The contract reverts when calling paused, like if the pausable module was not present.
  • on construction, the contract emitted an event that comes from the initializable module, which your source code does not include.

So you definitely did not deploy etherscan.io/address/0x5aae026d0d9f261903f803994d406ecf3c5162f8