I want to know why I can't call the getTokenId()
read function on the cloned UUPSUpgradeable
contract.
I cloned the contract and called the initialize()
function on the instance correctly.
The write function createAgent()
works fine, but the read function getTokenId()
doesn't work, so I reverted it.
And I tested the entire original contract and it works fine.
Code to reproduce
contract BEP007Enhanced is
IBEP007,
ERC721Upgradeable,
ERC721EnumerableUpgradeable,
ERC721URIStorageUpgradeable,
ReentrancyGuardUpgradeable,
OwnableUpgradeable,
UUPSUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
CountersUpgradeable.Counter private _tokenIdCounter;
function initialize(
address governanceAddress
) public virtual initializer {
require(governanceAddress != address(0), "BEP007Enhanced: governance address is zero");
__ERC721_init(name, symbol);
__ERC721Enumerable_init();
__ERC721URIStorage_init();
__ReentrancyGuard_init();
__Ownable_init();
__UUPSUpgradeable_init();
governance = governanceAddress;
_transferOwnership(governanceAddress);
}
function createAgent(string memory metadataURI) external {
_tokenIdCounter.increment();
uint256 tokenId = _tokenIdCounter.current();
_mint(to, tokenId);
_setTokenURI(tokenId, metadataURI);
}
function getTokenId() external view returns (uint256) {
return _tokenIdCounter.current();
}
}
Environment
Hardhat test environment