ERC20 Coding using openzipplin error

Hello again,

I’m following through the video on creating a ERC20 token exercise in the Ethereum smart contract 201 course. I’ve followed the steps with Fhilip in installing openzepplin using npm, and initialing truffle. However, when I tried to import the ERC2.sol library and compile the code, I run into the following problem(s). Anyone have an idea what’s going on?

note: I’ve included the pragma solidity version into truffle-config.js file as well, and it doesn’t seems to solve the problem

Hi @Philip_Wong

Can you check the installed version of @openzeppelin/contracts in your package.json file?

If you are using the latest openzepplin package version ^4.8.1 then try using the below solidity compiler version, to fix the error on line 2. As the latest ERC20 contract requires this compiler version.

pragma solidity >0.8.0;

and while running the truffle compile use the reset flag to reset and compile.

truffle compile --reset --all

Also before running this command make sure to update the truffle version in truffle-config.js to a version greater than 0.8.0

Let us know if this solves the errors.

Hi John,
I did tried those, but it didn’t seems to work. but what when I close the project folder and reopened it, the issues is fixed automatically.
I’m not sure is it because I haven’t install VS code correctly and/or import the libraries correctly.

1 Like

Glad it is solved🙌.
It is probably related to some local cache issue. If the similar issue happens again you can try updating or reinstalling the vs code.

1 Like

@JohnVersus
Hi again,
I’m on the Creating Wallet tests part of the course, when I tried to run the command

truffle test

I got the following error message:

which suggested I’ve made some mistakes in the 2_token_migration.js. blow is the said contract, which I’m pretty sure it is the same as what filip has done, yet I still get an error message, so can you please point me on where I’ve did wrong. thanks.

const Link = artifacts.require(“Link”);
const Dex = artifacts.require(“Dex”);
module.exports = async function(deployer, network, accounts){
await deployer.deploy(Link);
let dex = await Dex.deployed();
let link = await Link.deployed();
await link.approve(dex.address, 500);
dex.addToken(web3.utils.fromUtf8(“LINK”), link.address);
await dex.deposit(100, web3.utils.fromUtf8(“LINK”));
let balanceOfLink = await dex.balances(accounts[0], web3.utils.fromUtf8(“LINK”));
console.log(balanceOfLink);
};

Try moving this line after the dex.addToken line. As the token should be created first, then approved and deposited.

1 Like

yup fixed it. thanks

1 Like