1

I'm trying to find a way round using the ERC721Enumerable.sol extension because it essentially doubles the gas fees on minting but the tokenOfOwnerByIndex() function is a bit of an essential for what i'm doing. I basically want to get a list of all the token ids owned by a particular address as quickly and easily as possible.

Anyone have any thoughts on a workaround? Even something off-chain? I did have something going using the Etherscan API to query a wallet and then sort though results to get the tokens they own but it can be a little slow. I have also tried Moralis.io but they can take a few minutes to index onchain events which can be an issue for UX in my particular use case.

2 Answers 2

0

OZ's ERC721Enumerable has 2 functionalities basically: enumeration of tokens by owner, and enumeration of all tokens. Since you need only the enumeration by owner, you can remove from their implementation everything dealing with _allTokens and _allTokensIndex. This will probably save around half the gas costs.

0

If you develop a contract by yourself, you are able to write your own functionality.

Just create a structure which will store ids of tokens per user address:

mapping(address => uint256[]) private _tokensByAddress;

On mint a new token, transfer or burn methods calls update this dataset. It would be good to write a test suite to confirm your implementation is stable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.