ERC721Enumerable, gas cost and infinite supply

Hi,

I'm new to smart contract dev and was playing around with OpenZeppelin's wizard. The "Enumerable" checkbox hinted that implementing enumeration will "Increases gas cost of transfers". Can anyone explain how is it so? Also, will the gas cost increases as the number of tokens increases? I'm planning to develop an ERC721 token that has no max supply/cap.

Thanks!

1 Like

Adding the enumeration property to an ERC721 token adds quite a bit of extra storage to the inheriting NFT contract, specifically it adds 3 new mappings and an array that must be updated with each token minting event and transfer event. However, the enumeration property is quite useful as you can call tokenOfOwnerByIndex(address owner, uint256 index), tokenByIndex(uint256 index), and totalSupply() which makes is much easier to build paginated user interfaces. These methods are not available without the enumeration property. Additionally, the gas cost is constant with respect to the total supply, i.e. the computational complexity to add a new NFT to the list is not a function of the size of the list.

2 Likes