1

I am trying to run the code which is generating an error stating that DeclarationError: Identifier not found or not unique. The smart contract NFTCollection is a solidity code which enables me to mint a specific number of ERC721 Tokens and to count the tokens of owner. I am receiving a error while displaying the error message "DeclarationError: Identifier not found or not unique" at line 20 which reads "using Counters for Counters.counter;" Please find the code below. Any help would be highly appreciated.

The contract and the error message.

pragma solidity ^0.8.4;
// Importing required libraries
/*
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/591c12d22de283a297e2b551175ccc914c938391/contracts/token/ERC721/ERC721.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/591c12d22de283a297e2b551175ccc914c938391/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/591c12d22de283a297e2b551175ccc914c938391/contracts/utils/Counters.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/591c12d22de283a297e2b551175ccc914c938391/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
*/


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

 // This is a simple NFT contract
 //Start of a contract
 //INitialising contract as a ERC721, ERC721Enumerable, Ownable contract.
 contract NFTCollection is ERC721, ERC721Enumerable, Ownable {
    using Counters for Counters.counter;

    // Specifing the maximum supply
    uint256 maxSupply = 1000000;
    // Initiatina a counter to store to be able to use Counters on uint265 without impacting the rest of the uint256 in the contract.
    //Counter helps to find every function from a single library to a type to reduce gass fee.
    Counters.Counter private _tokenIDCounter;
    // Initialising a constructor.
    constructor(string memory _name, string memory _symbol)
        ERC721(_name, _symbol){}
        // ERC721 interface is initialised and the _name, _symbol details aere passed in to hold.
        //End of constructor. 
        //Start of function mint.
        //This function is used to mint ERC721 tokens. 
        //Mint function adds the capability to mint ERC721 tokens and assign it to a address which accepts user address, number of tokens as arguments. 

        function mint(address _user, uint256 _amount) public {
            //Start of for loop
            for(uint256 i;i<_amount;i++)
            {
                //Incrementing the  _tokenIdCounter by 1 using increment function.
                _tokenIdCounter.increment();
                // Creating a variable which stores the current value of _tokenIdCounter.
                uint256 tokenId = _tokenIdcounter.current();
                //Using safemint to mint ERC721 Tokens.
                _safeMint(_user,tokenId);
            }
        }//End of function mint. 

        //Start of function tokensOfOwner
        // This function is used to keep track of the owners Tokens. 
        // The function seeks a owner address to check the number of tokens he owns. 
        function tokensOfOwner(address _owner) public view returns (uint256[] memory)
        {   // Creating a ownerTokenCount which stores the balance of the owner.
            uint256 ownerTokenCount = balanceOf(_owner);
            // Creating a memory variable and storing a array of ownerTokenCount. 
            uint256[] memory ownedTokenIds = new uint256[](ownerTokenCount);
            for (uint256 i; i < ownerTokenCount; ++i) {
                ownedTokenIds[i] = tokenOfOwnerByIndex(_owner, i);
            }//End of for loop
        return ownedTokenIds; //Return statement.
    }
    // Function overrides required by solidity
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal override(ERC721, ERC721Enumerable) {
        super._beforeTokenTransfer(from, to, tokenId);
    }

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


 }

Error Message

--> contracts/nft.sol:20:24:
|
20 | using Counters for Counters.counter;~~~
  • 3
    `Counters.Counter` with capital letter – Yilmaz Feb 05 '23 at 04:47
  • As @Yilmaz mentioned, the Counter needs to be with a capital C. Also, you are declaring _tokenIDCounter but referencing the variable with _tokenIdCounter (without capital D) on lines 41&43. – Alon Ben Yaakov May 20 '23 at 12:12

0 Answers0