I have a smartcontract that generates NFTs. I can check who the owner of a NFT is, because by minting, the sender of the payment can be set to be the owner. address to
will be the receiver and owner of the token.
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
A smartcontract tracks the owner who intially bought or minted the token.
But now the owner who has the token in his wallet could send the token by himself to another wallet right? But how does the smartcontract change who the owner is, if the token is send from one wallet to another ? By change i mean the mapping tokenID -> OwnerAddress
that is tracked by the smartcontract.
from oppenzeppelin ERC721 this mapping stores the mapping between tokenID and Owner address and the function to check it. How can this method work if the NFT is transfered independently ? or i got it wrong and the token is not send idependently.. and then it makes sense. Because transfering a NFT from one wallet to another wallet is always calling the transferto
function of the smartcontract that created/minted the token. is that right?
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
/**
* @dev See {IERC721-ownerOf}.
*/
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;
}
So a NFT is just a state of a smartcontract? and i can just check who the owner of a tokenID is by calling the function on the smartcontract which created the Token? And the fact that a wallet can hold NFTs is just a state of a smartcontract that keeps track of the tokens which where created by it and it always knows where the tokens are because all tokens are just states of a smartcontract?! ahh ;)