ERC721 minting?

Hi everyone, I have had a question that I somewhat need a a clearer answer on. If I own an ERC721 contract.Then a user uses the mint function, how does that person eventually become an NFT owner, while I deployed the contract and I own it, but in their wallets it will show as they own an NFT? I'm just unclear on how all that connects with the wallet?

Hi, welcome! :wave:

I think you can have a look at the code:
openzeppelin-contracts/ERC721.sol at master ยท OpenZeppelin/openzeppelin-contracts (

    function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");

        _beforeTokenTransfer(address(0), to, tokenId);

        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(address(0), to, tokenId);

So it depends on how do you rewrite the function mint, you can add permission to this function, so only you can mint.

thank you so much @Skyge. well I understand the code very well. I have been developing smart contracts for a while. but I was wondering how does this code connect to the wallet of a user? so when they mint a new NFT, the new NFT they minted will show in their wallet but yet I still own the smart contract! I'm not asking why because that makes sense but how does the wallet know, since all this function does is basically adds one for the user balance. or does the wallet fetch the nft through the setTokenURI since that function has access to token URI?

I think just like if you have some USDC, how doe it show in the wallet? The wallet should know the USDC contract address, and then it can check your balance. So when a user mint a new NFT, the wallet should know the NFT contract address, as for how does the wallet know this, I am not sure for this, maybe you can have a look at how does MetaMask to show the balance of the new token.

OOOOh, thank you so much that makes so much sense!