flow-nft
flow-nft copied to clipboard
Impossible to count number of NFTs in large collections and get the IDs
Issue to be solved
getIDs().length breaks when used on accounts with large NFT collections like 0x329feb3ab062d289.661249
failed to retrieve slab 0x329feb3ab062d289.661249: get value failed: [Error Code: 1110] computation exceeds limit (100000)
Suggested Solution
- Add way to get the count of total NFTs by avoiding
getIDs().length - Add way to get a slice of the IDs in the collection.
@joshuahannan I'm tagging you here as this might be interesting for the V2 standard.
yeah I would love if we could find a solution for this that we could use with the standard
These improvements are all related to the NFT standard, moving
Can this be done with what we have currently? I'd guess we might have to tackle it with the V2 standards coming out with stable cadence. The main issue as I understand it is that getIDs has to load all IDs into memory which is just too costly for large collections
To allow users to query the size of the collection, Collection should provide a getter function for it, so that users do not need to rely on the inefficient getIDs().length.
This is simple by adding:
fun getCount(): Int
return ownedNFTs.length
}
Looks good for getting ID count, any idea on getting a slice of the IDs without loading all of them with getIDs ?
Maybe a function to return:
ownedNFTs.slice(from: upTo:) , loop through them get the IDs and return them
Yeah, I think getting a slice like that will require an update to Cadence
I added getLength to the new standard btw
You could do iteration over the map and fetch the first x ones?
getLength addresses this so I am closing