I'm trying to compile this code using the Truffle command truffle compile

pragma solidity ^0.6.0;

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

contract GLDToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("Gold", "GLD") public {
        _mint(msg.sender, initialSupply);

It's basically a copy-paste from the openzeppelin official documentation.

This code woks perfectly in Remix IDE, but when I try to run it with Trufffle, I got this error:

Error parsing @openzeppelin/contracts/token/ERC20/ERC20.sol: ParsedContract.sol:98:40: ParserError: Expected '{' but got reserved keyword 'override'
    function totalSupply() public view override returns (uint256) {
Compilation failed. See above.
Truffle v5.0.5 (core: 5.0.5)
Node v10.16.3

Does anyone know what to do?



I changed the version of the solidity compiler as recommanded by goodvibration and I got another error:

TypeError: Error parsing C:/tutorial-token/contracts/Migrations.sol: Cannot read property 'addFunction' of undefined
    at runWithReadCallback (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\solc\wrapper.js:37:1)
    at compileStandard (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\solc\wrapper.js:78:1)
    at Object.compileStandardWrapper (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\solc\wrapper.js:85:1)
    at Object.parseImports (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\parser.js:47:1)
    at Object.getImports (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\profiler.js:374:1)
    at Promise.all.then.results (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\profiler.js:346:1)
Truffle v5.0.5 (core: 5.0.5)
Node v10.16.3```
  • That's a completely different error, which you should post as a separate question, since this is not a discussion platform, where you refer to answers by updating your question. And if the given answer has answered your previous question (i.e., by solving the specific problem described in it), then please accept that answer by clicking on the V next to it. Jun 19 '20 at 12:08

Truffle 5.0.5 uses solc 0.5.x by default (not sure about the value of x).

The override keyword is supported only from solc 0.6 onward.

You should add in your Truffle configuration file:

compilers: {
    solc: {
        version: "0.6.0" // or find out what the latest version is and use that instead

See here for more details.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.