0

I am trying to write an ERC721 contract that tracks and iterates tokenId using counters.sol from Openzepplin, so that I can manually change the tokenURI to store data on chain. Here is the code throwing an error:

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/Counters.sol";
// import ..... (multiple imports)

contract ContractName is ERC721URIStorage, Pausable, ReentrancyGuard, Ownable {

   function FuncName(string memory _top, string memory _content, string memory _bottom) public nonReentrant payable returns (string memory) {

      using Counters for Counters.Counter;
      Counters.Counter private _tokenIds;

And from this I get the following error:

CompileError: ParserError: Expected primary expression at using

Any help would be greatly appreciated.

1 Answer 1

0

You should declare

using Counters for Counters.Counter;
Counters.Counter private _tokenIds;

inside the contract, not inside the function FuncName. Should look like this:

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/Counters.sol";
// import ..... (multiple imports)

contract ContractName is ERC721URIStorage, Pausable, ReentrancyGuard, Ownable {
      using Counters for Counters.Counter;
      Counters.Counter private _tokenIds;

   function FuncName(string memory _top, string memory _content, string memory _bottom) public nonReentrant payable returns (string memory) {

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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