tokenId increment using Counter.sol not working

Hi,
I want to create ERC721 token for each application form submitted by user(where their application number is using Counter.sol increment function) and next time when application form opens up i would like to get next incremented value as its application number,now I get only 1 as application number & after token creation not getting next incremented value
For Example : first form Application number 1 then token 1 and mint token to address 1
Next Application number 2 then token 2 and mint token 2 to address 1
next application number 3 then token 3 to address 2 and so on

Truffle v5.4.6 (core: 5.4.6)
Solidity v0.5.16 (solc-js)

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;

import "@openzeppelin/contracts/token/ERC721/ERC721Full.sol";
import "@openzeppelin/contracts/drafts/Counters.sol";

contract MyToken is ERC721Full {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() public ERC721Full("MyNFT", "MNFT") {
     
    }
    //Get unique application number on application form
    function getApplicationNo() public returns (uint256) {
           _tokenIds.increment();
        return _tokenIds.current();
    }

    //Create token for an application which can be tracked
    function mintToken(address owner, string memory tokenURI)
        public
        returns (uint256)
    {
        uint256 newItemId = _tokenIds.current();
       _tokenIds.increment();
        _mint(owner, newItemId);
        //set token with its URI -JSON format
        _setTokenURI(newItemId, tokenURI);

       
        return newItemId;
    }

The problem is obviously in your offchain code (truffle test or other), as there is nothing here which can be "not working".

Hey @Jisa_Anu_Mathew,

If I understand it correctly, you want to get identifying NFT numbers for a form (I supposed in a frontend), is that correct?

Few things:

  1. I don't see why getApplicationNo exists. It's public, therefore, it'll cost gas just to call and will mutate the state, while my understanding is that you just want the number
  2. The contracts you're using are from the OpenZeppelin 2.x docs, not sure if it's not working at compilation, but if that's the case, can you try with these?

Also curious to know, did you get to the 2.x docs through Google Search?

1 Like

Thank you @ernestognw
That's what I want.
I have used getApplicationNo to get my new tokenid incremented to frontend.
since i am using solc version 5.4 i have checked with documentation for openzepplin 2.x,will try to update it and check if it works.

I got 2.x from documentation available in openzepplin official site.