ERC-721 – Resolving ‘Undeclared Identifier’ and ‘totalSupply()’ Errors when Inheriting from ERC721Enumerable

erc-721soliditytypescript

've just started learning solidity and I tried to make a contract .

I getting error due to totalSupply() are Undeclared identified .

contract BYYCC is ERC721, Ownable {

    using SafeMath for uint256;

    string public BAYC_PROVENANCE = "";

    uint256 public startingIndexBlock;

    uint256 public startingIndex;

    uint256 public constant apePrice = 80000000000000000; //0.08 ETH

    uint public constant maxApePurchase = 20;

    uint256 public MAX_APES;

    bool public saleIsActive = false;

    uint256 public REVEAL_TIMESTAMP;

    constructor(string memory name, string memory symbol, uint256 maxNftSupply, uint256 saleStart) ERC721(name, symbol) {
        MAX_APES = maxNftSupply;
        REVEAL_TIMESTAMP = saleStart + (86400 * 9);
    }

enter image description here

I 've try import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol" .it resolve the totalSupply() are Undeclared identified but another Error when inherit from ERC721Enumerable and ERC721 at the same time

Derived contract must override function "_beforeTokenTransfer". Two or more base classes define function with same name and parameter types.

Derived contract must override function "supportsInterface". Two or more base classes define function with same name and parameter types.

enter image description here

Best Answer

That's because ERC721Enumerable already inherits from ERC721. For this reason, functions are colliding. To solve this, just import ERC721Enumerable in your contract like so:

contract BYYCC is ERC721Enumerable, Ownable {

}