Here is the contract code to mint ERC721 tokens:

contract NFT is ERC721URIStorage, Ownable {

    mapping(uint256 => address) private _owners;
    mapping(address => uint256) private _balances;

    constructor()ERC721 ("Lambo", "LMB") public {}

    function mintNFT(address to, uint256 tokenId, string memory tokenURI) public {
        require(to != address(0), "ERC721: token mint to contract owner address");
        require(!_exists(tokenId), "ERC721: token already minted");
        _mint(to, tokenId);
        _setTokenURI(tokenId, tokenURI);

    function burnToken(uint256 tokenId) public {

    function balanceOf(address owner) public view virtual override returns (uint256) {
        require(owner != address(0), "ERC721: balance query for zero address");
        return _balances[owner];

    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        address owner = _owners[tokenId];
        return owner;

Writing tests to mint ERC721 tokens and verify if the minted addresses owns the token:

const firstMinter = accounts[4]; //0xD235287FcBE172407F5692Bc25cD73989a7d6777

it("Minting ERC721 Tokens", async() => {
        let nftInstance = await mintNFTs.deployed();

        await nftInstance.mintNFT(firstMinter, 1, "ipfs://QmQZTUekV9P7cKRiVVwdahyaFNZEt6Yt7fGtcRfsLSWpyP/evocube.json");

        console.log("ERC721 Tokens have been minted for whitelist")

    it("Verifying Whitelist Owners have ERC721 Tokens", async() => {

        const nftInstance = await mintNFTs.deployed();

        let firstOwner = await nftInstance.ownerOf(1);
        assert.equal(firstMinter, firstOwner, "Error: First Minter doesn't own the token");

Here are the test results I am receiving:

AssertionError: Error: First Minter doesn't own the token: expected '0xD235287FcBE172407F5692Bc25cD73989a7d6777' to equal '0x0000000000000000000000000000000000000000'

  • 1
    I think your deployed contract might be a fresh instance each time you call the deployed. Try to validate by calling total supply. Apr 20, 2022 at 12:27
  • I merged NFT owner verification code within the mint code yet it's giving the same error. Apr 20, 2022 at 14:46
  • So you might want to test further to figure out why? BalanceOf, total Supply, did the Mint happen correctly? Apr 20, 2022 at 15:25
  • Which ERC721 contract are you using? Apr 20, 2022 at 15:26
  • Which ERC721 as in the token ID? It's minted with id 1 and queried for Id 1 Apr 20, 2022 at 16:20

1 Answer 1


I think your problem is here, the firstMinter is still haven't own the NFT yet before deployed tokenID 1, so the firstOwner is null.

assert.equal(firstMinter, firstOwner, "Error: First Minter doesn't own the token");

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.