ERC721 NFT Begginer doubts

Hi,

I am learning about the smart contract world, so, maybe it is a stupidity but I need to ask.

I defined my metadata file with 2 tokens and very basic ERC721 contract from wizard:

{
	"token1":
	{
	"id":0
    	"name": "Token 1",
    	"description": "Token1 Description,
    	"image": "https://mydomain.com/token1.jpg"
	},
	"token2":
	{
	"id":1
    	"name": "Token 2",
    	"description": "Token Description",
    	"image": "https://mydomain.com/token2.jpg"
	}
}
/ SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract myNFT is ERC721, ERC721URIStorage, ERC721Burnable, Ownable {
    constructor(address initialOwner)
        ERC721("myNFT", "NFT")
        Ownable(initialOwner)
    {}

    function safeMint(address to, uint256 tokenId, string memory uri)
        public
        onlyOwner
    {
        _safeMint(to, tokenId);
        _setTokenURI(tokenId, uri);
    }

    // The following functions are overrides required by Solidity.

    function tokenURI(uint256 tokenId)
        public
        view
        override(ERC721, ERC721URIStorage)
        returns (string memory)
    {
        return super.tokenURI(tokenId);
    }

    function supportsInterface(bytes4 interfaceId)
        public
        view
        override(ERC721, ERC721URIStorage)
        returns (bool)
    {
        return super.supportsInterface(interfaceId);
    }
}

My doubt, how should I mint each token?, for example, token1 for address A and token2 for address B. Should I change the safeMint function o call it in some different way? I was looking for code examples but always there are only a token in each metadata file.

Best regards,

Automatically when minting one at a time, the _tokenId will increase, so in the first mint, it will be id 0 with the name "Token 1" and its respective image, in the second mint it will be id 1, with the name "Token 2" and its respective image

1 Like