Learning Openzeppelin

Hey mate, I’m sure you figured it out already - but try replacing your import with:

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";

Just remove the ../node_modules/.
It worked for me! :slightly_smiling_face:

1 Like

Hey @jak, this worked for me too, thanks for the solution! Do you know why this works, and not the way @filip codes it in the video? I can’t make sense of it…

I would just guess outdated version and maybe standards have changed. Perhaps try an older v of solidity. Seeing as the current openzeppelin code ships in 0.8.0 and it’s 0.6.x in @filip’s vids.

Bit of a dick around with time but probably good to have to explore the openzep forums and community whilst trying to find the answer haha

1 Like

Hi all,

On the Truffle console, I executed:
let instance = MyToken.deployed()

and it returned undefined which is fine.

But when I run:
instance.decimals()

I got the following error shown in the screenshot below:

Openzeppelin Uncaught TypeError

What have I done incorrectly? What should be done to fix this error? I just did exactly what Filip did in the video. . .

Any help would be much appreciated :slight_smile:

1 Like

In the chapter “Extending ERC20”, I just typed in the same details of the contract MyToken as Filip did in the video. However, I couldn’t compile the contract and came across the following error shown in the screenshot below:

Extending ERC20 immutable error

TypeError: Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier 
called from it.
  --> project:/node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol:26:16:
   |
26 |         return _cap;
   |                ^^^^

Compilation failed. See above.

Has anyone come across the same error as I have? How are we supposed to edit the contract “ERC 20 Capped.sol” ?

Any help would be much appreciated :grinning:

Hi @BUILTOCKCHAIN, I was getting the same error as well and searched it elsewhere on the web and found the following https://github.com/OpenZeppelin/openzeppelin-contracts/issues/2580. Here’s the fix:

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

import "../node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";

contract MyToken is ERC20Capped {
    constructor () ERC20("My Token", "MTKN") ERC20Capped(100000){
        ERC20._mint(msg.sender, 200000);
    }
}

I would also like to add that in the link I provide, they mention this is not a general fix. I just tried to migrate and it didn’t give me the error that it exceeded the cap - but it did allow me to compile. I’m not 100% sure at the moment how to prevent overproduction of our token.

1 Like

I somehow have problems with the integration of the Openzeppelin contracts. I followed filips steps, but i always get some unexpected messages.

  1. Somehow i can´t Mint and the Balance doesn´t change
  2. When i tried to execute the “instance.owner()” code i recieved this:
    Screenshot (204)
1 Like

Hey @Leonard_Gohlke, hope you are well.

Could you please share your contract code in the following way so we can help you review the error?

Carlos Z

@thecil

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

import "../node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";


contract MyToken is ERC20Capped, Ownable {
    constructor() ERC20("MyToken", "LAG") ERC20Capped(100000){
        _mint(msg.sender, 200000);
    }
}

The Migration:

const MyToken = artifacts.require("MyToken");

module.exports = function (deployer) {
  deployer.deploy(MyToken);
};

1 Like

Hey @thecil i figured it out. It works now, thanks!

1 Like

@thecil @admins

Hi All, currently having issues migrating the multi-sig contract.

const MultiSig = artifacts.require("MultiSig");

module.exports = function (deployer, accounts) {
    deployer.deploy(MultiSig,[0xefcd1b2404eaf3095fdac6e26d33be87dc88b111, 0x9bc44a1c3594aca3783eb5e0976ddcb7e899b059, 0xde4a47abb9d29455309f0f036be35483ebe12401], 2);

};

I used the exact project code from the git repo so didn’t feel the need to post.

I’m inputting the correct format for the arguments and also in the correct order (My contracts name is “MultiSig”, how can I get this to work?

I fail with the below error:

"MultiSig" -- invalid address (argument="address", value=1.3690228112810186e+48, code=INVALID_ARGUMENT, version=address/5.0.5) (argument=null, value=1.3690228112810186e+48, code=INVALID_ARGUMENT, version=abi/5.0.7).
1 Like

Hey @donhuey, hope you are well.

You just have to send the addresses as string type, meaning:
["address", "address"]

["0xefcd1b2404eaf3095fdac6e26d33be87dc88b111", "0x9bc44a1c3594aca3783eb5e0976ddcb7e899b059", "0xde4a47abb9d29455309f0f036be35483ebe12401"]

Hope it helps.

Carlos Z

Hi guys, I hope that you are fine.

When I changed the pragma solidity versione of ERC20.sol file to “>=0.6.0 <0.8.0” has appeared an error in the middle of the file, there it is:

project:/node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol:159:9: 
ParserError: Expected primary expression. 
        unchecked {

Anyone else had this problem?

all right guys, i just refresh cmd and now compile works, even if visual studio tell me that there is the error.

1 Like

Thanks @jak I was having the same issue and is now working🤩

Hello all I have a quick question about the total supply. So I used erc20 preset from openzippline I have used ERC20FixedSupply, I am wondering how can I pass a big number (i.e. 800 million) while also having the decimals as 18?
when I tried to write 800 million + 18 zeros that is
8000000000000000000000000 (800 million + 18 zeros) so that I have the right total supply javascript in the migration file complained that its a big number my only work around is to lower the decimals, is there anyway I keep decimals as 18 and set total supply to 800 million?

1 Like

yeah javascript doesnt like big numbers, try web3.utils.toWei("800", "ether")

1 Like

thank you that’s right.

Hi! When I want to check balance of owner account it shows different data than you had in video. Can you explain what does it mean? Thanks in advance!

pragma solidity ^0.8.0;

import "../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract myToken is ERC20 {
    constructor() ERC20("myToken", "MTKN") {
        _mint(msg.sender, 1000);
    }
}


I can’t get the path right. I tried solutions on stack overflow for this problem and did some tinkering with the extension settings too but no solution seems to work for me.

1 Like