Search code examples
smartcontractsnft

Where is the owner of an nft is stored?


I know the nft is minting through a smart contract into the blockchain. But where is the owner wallet stored? and also changing the owner requires additionl smart contract?


Solution

  • Owner address of each token is stored in its collection contract.

    The ERC-721 standard only defines that the owner should be retrievable by calling the ownerOf() function, passing it the token ID as the only argument. It doesn't define how exactly the information should be stored.

    But many implementations use a mapping. For example the OpenZeppelin implementation:

    mapping(uint256 => address) private _owners;
    
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        address owner = _owners[tokenId];
        require(owner != address(0), "ERC721: owner query for nonexistent token");
        return owner;
    }
    

    changing the owner requires additionl smart contract?

    Assuming the collection contract follows the standard, it's able to change the token owner (i.e. transfer the token) by executing any of the transfer functions from the owner's (non-contract) address.

    So it doesn't require an additional smart contract to transfer a token.