Get Address Token Owned

Add userOwnedTokens

mapping(address => uint256[]) public userOwnedTokens;
mapping(uint256 => uint256) public tokenIsAtIndex;

function get_address_token(address _add,uint256 _i) external view returns(uint256){
	return userOwnedTokens[_add][_i];
}

_mint()

Add arrays into your do while loop in mint() and comment out your _afterTokenTransfers since we'll use this on transfer function

uint256 tokenId = startTokenId;
uint256 end = startTokenId + quantity;
do {
    userOwnedTokens[msg.sender].push(tokenId);
    emit Transfer(address(0), to, tokenId++);
} while (tokenId < end);
uint256 arrayLength = userOwnedTokens[msg.sender].length;
tokenIsAtIndex[tokenId] = arrayLength;

Inside mint function, comment out _afterTokenTransfers

// _afterTokenTransfers(address(0), to, startTokenId, quantity);

_afterTokenTransfers()

delete quantity as we will only be calling this function for transfer tokens and assign new owner of X token ids to [to] address.

Dont forget to set [from][tokenIndex] to numbers that exceed your supply.

function _afterTokenTransfers(
        address from,
        address to,
        uint256 startTokenId
    ) internal virtual {
	uint256 tokenIndex = tokenIsAtIndex[startTokenId];
    	userOwnedTokens[to][tokenIndex] = startTokenId; 
    	userOwnedTokens[from][tokenIndex] = 100000; 
}

Delete quantiy in all functions that call _afterTokenTransfers()

//from
_afterTokenTransfers(address(0), to, startTokenId,1);
//to
_afterTokenTransfers(address(0), to, startTokenId);

Last updated

Was this helpful?