0

When I try to compile my smart contract using truffle, it comes up with this error: Error parsing @openzeppelin/contracts/token/ERC721/ERC721.sol: ParsedContract.sol:51:72: ParserError: Expected '{' but got reserved keyword 'override'.

My Smart Contract:

pragma solidity 0.5.0;

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

contract Color is ERC721 {} 

Does anyone know how to fix this? I know that this is not a new question, but I haven't found a stack overflow or other forum solution that has worked for me. Thanks in advance.

3 Answers3

0

So your problem is that int the ERC721 contract there is a constructor(string memory, string memory) function which accepts two parameters, the first is the NFT token name and the second is the NFT token symbol.
When you are inheriting the ERC721 contract in your color contract you have to define a constructor function which to trigger the constructor of the ERC721 contract.
In nutshell you should modify your contract as follows:

  contract Color is ERC721 { 
    constructor(string memory name, string memory symbol) ERC721(name, symbol) { }
  }

or if you want to have pre-set name and symbol you can do this:

  contract Color is ERC721 { 
    constructor()  ERC721("Name", "Symbol") { }
  }

Edit

Make your file's code as follows:

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

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

contract MyCollectible is ERC721 {
    constructor() ERC721("MyCollectible", "MCO") {
    }
}

Also be sure that you have run npm install @openzeppelin/contracts

Hristo Todorov
  • 263
  • 2
  • 12
0

I know this is an old post, but I had this same issue recently. For me, the issue was that my compiler was running an old version of Solidity. Once I changed my compiler's version to the latest, this error was resolved.

At the top of the file for which I was getting the error, I had:
pragma solidity >=0.4.22 <0.9.0;

My compiler was using version 0.5.1. To fix it, I changed my compiler settings to use version 0.8.12.

NFab
  • 386
  • 4
  • 6
0

That's because the contract you're importing is written for solidity 0.8 and up. You won't be able to use an older version. Simply change your first line to:

pragma solidity 0.8.0;

And it will be fixed. You can see that the imported contract is using 0.8.0.