In an ERC721 contract how to create a status variable that saves -1 to indicate that an nft owner address no longer owns it because it has decided to transfer it to another address.
In order to achieve this result, I tried to replicate an approach found here
I used as follow.
- create two mappings
mapping(address => uint256[]) public userOwnedTokens;
mapping(uint256 => int256) public tokenIsAtIndex;
- then create a function that update these mapping when a nft token is minted
function createNft(string memory _tokenURI, address to) onlyOwner public returns (uint256)
{
_tokenIds.increment();
uint256 newTokenId = _tokenIds.current();
_mint(msg.sender, newTokenId);
_setTokenURI(newTokenId, _tokenURI);
userOwnedTokens[msg.sender].push(newTokenId);
int256 arrayLength = int(userOwnedTokens[msg.sender].length);
tokenIsAtIndex[newTokenId] = arrayLength;
return newTokenId;
}
- So I need to save -1 to indicate that the user moved the nft in the following way:
// Inside a transfer logic
uint256 tokenIndex = tokenIsAtIndex[tokenId];
userOwnedTokens[from][tokenIndex] = -1; // TO DENOTE THAT THE TOKEN HAS BEEN TRANSFERRED, YOU CAN USE ANY OTHER NUMBER
So the the question here is how can I override in example transferFrom or safeTransferFrom in order to set -1 every time someone transfer the nft.