How to read the current minted token id using ERC721 preset

Need to get the “current” tokenId to use it in other functions.

How would a contract implementing ERC721PresetMinterPauserAutoIdUpgradeable acces the current counter, before the minting process (ar after it)

:computer: Environment
@openzeppelin/contracts-upgradeable”: “^4.0.0”,
“truffle”: “^5.3.1”


Example solution that does not work because of private _tokenIdTracker

TestContract is ERC721PresetMinterPauserAutoIdUpgradeable {
//would not work private varibale _tokenIdTracker
 function getCurrentCounter() public view returns (uint256){
    return _tokenIdTracker.current();
1 Like

Hi @intoverq,

State variables are private and there isn’t a getter that you can use.

Instead you can use the ideas from the Preset and create your own contract extending from ERC721.

See the documentation:

Also the Contracts Wizard:

1 Like

That’s would be the solution, thanks for confirming it

1 Like