Compiler 0.8.13 and above, occur issues when override approve() function

I am using Remix to compile the contract. When I choose the compiler lower than 0.8.13, it works fine. but I choose 0.8.13 or higher compiler, will get an error. Could somebody help?

**The Contract Code: **

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

import "@openzeppelin/contracts@4.8.0/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.8.0/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts@4.8.0/access/Ownable.sol";

contract MyToken is ERC721, ERC721Enumerable, Ownable {
    constructor() ERC721("MyToken", "MTK") {}

    function safeMint(address to, uint256 tokenId) public onlyOwner {
        _safeMint(to, tokenId);

    // The following functions are overrides required by Solidity.

    function _beforeTokenTransfer(address from, address to, uint256 tokenId, uint256 batchSize)
        override(ERC721, ERC721Enumerable)
        super._beforeTokenTransfer(from, to, tokenId, batchSize);

    function supportsInterface(bytes4 interfaceId)
        override(ERC721, ERC721Enumerable)
        returns (bool)
        return super.supportsInterface(interfaceId);

    function approve(address to, uint256 tokenId) public virtual override {
        to; tokenId;
        require(false, "!");

The Error message

TypeError: Function needs to specify overridden contracts "ERC721" and "IERC721".
--> contract-eae06bf068.sol:34:66:
34 | function approve(address to, uint256 tokenId) public virtual override {
| ^^^^^^^^
Note: This contract:
--> @openzeppelin/contracts@4.8.0/token/ERC721/ERC721.sol:19:1:
19 | contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
| ^ (Relevant source part starts here and spans across multiple lines).
Note: This contract:
--> @openzeppelin/contracts@4.8.0/token/ERC721/IERC721.sol:11:1:
11 | interface IERC721 is IERC165 {
| ^ (Relevant source part starts here and spans across multiple lines).

Hey @Olive-l,

I tried to replicate in Remix and indeed it failed when I changed the compiler version, but I noticed it's trying to compile with the version I had originally in my URL.

If you change the compiler version it will be updated on the search bar but you might need to reload the page to load the compiler from the very beginning.

I tried that with 0.8.13 and it worked.

Let me know if that helps. (If so, you may want to also share the bug with the Remix repo).


Hello Ernesto,
Thanks for your reply! I am not sure that do you mean you compile my code successfully? Could you depict how do you fix it more specifically?
I still get an error either. when I change the compiler version, and then reload the page of remix, I will lost my contract file. After I add a new contract of the same code, still failure as the same issue.

Add some more
If I remove the * ERC721Enumerable*, and include it's functions, it can be compiled successfully under 0.8.13 version.

Hi @ernestognw ,

Thx for your reply! Do you mean you compile successfully my code under v0.8.13? Could you be more specific how do you fix it?
I am not sure what's that mean: reload the page to load the compiler from very beginning. I still get the same error, even If I reload the remix page.

one more thing
If I delete the * ERC721Enumerable* and it's two functions, It can be compiled fine under 0.8.13

Thanks again!

I fixed this issue finally, omit the override objects:

function approve(address to, uint256 tokenId) public virtual override(ERC721, IERC721) {
        to; tokenId;
        require(false, "GreenPowerN-ID!");
1 Like

Hey @Olive,

Of course, let me add more detail.
I tried to replicate and I went to remix but my autocomplete set the compiler to 0.8.7 by default because of my URL, look:

What I did was changing the compiler in Remix, but they seem to have a bug loading the compiler again, so you have to reload the page with this URL:

This way, the compiler will load correctly and it will compile this way.

Glad you figure it out anyway,

override(ERC721, ERC721Enumerable)

override needs to have arguments in this case.