I have simple ERC721 contract which is successfully deployed and some of the NFT's are minted but when i call
MyERC721(collectionAddress).balanceOf(msg.sender);
I receive this error:
uint256 : Error: Returned error: execution reverted
Any idea how to handle it? Here is some additional source:
balanceOf function:
function balanceOf(address collectionAddress) external view returns(uint256) {
return MyERC721(collectionAddress).balanceOf(msg.sender);
}
MyERC721 contract:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract MyERC721 is ERC721 {
address owner;
constructor(string memory name_, string memory symbol_, address owner_) ERC721(name_, symbol_) {
owner = owner_;
}
function safeMint(address to, uint256 tokenId) external {
require(msg.sender == owner, "NOT_OWNER");
_safeMint(to, tokenId, "");
}
function safeMint(address to, uint256 tokenId, bytes memory data) external {
require(msg.sender == owner, "NOT_OWNER");
_safeMint(to, tokenId, data);
}
}
and i can see balance is 1 in etherscan:
CollectionManager source:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "./MyERC721.sol";
import "./interfaces/ICollectionManager.sol";
contract CollectionManager is ICollectionManager {
// Collection[] public allCollections;
mapping(address => address[]) public collectionsOf;
mapping(address => Collection) public collection;
function createCollection(string memory name, string memory symbol) external {
MyERC721 newCollection = new MyERC721(name, symbol, address(this));
address collectionAddress = address(newCollection);
address sender = msg.sender;
collection[collectionAddress].status = Status.Inactive;
collection[collectionAddress].owner = sender;
// allCollections.push(collection[collectionAddress])
collectionsOf[sender].push(collectionAddress);
emit CollectionCreated(sender, collectionAddress, block.timestamp);
}
function setCollectionActive(address collectionAddress) external {
collection[collectionAddress].status = Status.Active;
emit CollectionActivated(collectionAddress, block.timestamp);
}
function mint(address collectionAddress) external {
uint256 tokenId = collection[collectionAddress].tokenIdCounter + 1;
collection[collectionAddress].tokenIdCounter = tokenId;
MyERC721(collectionAddress).safeMint(msg.sender, tokenId);
}
function balanceOf(address collectionAddress) external view returns(uint256) {
return MyERC721(collectionAddress).balanceOf(msg.sender);
}
function totalSupply(address collectionAddress) external view returns(uint256) {
return ERC721Enumerable(collectionAddress).totalSupply();
}
}