F
Flow•9mo ago
Vishal | Flow

vishal (2024-03-01)

How to use the forEachCatalogKey method in the NFT Catalog while replacing NFTCatalog.getCatalog()? 🧵
2 Replies
Needle
Needle•9mo ago
I've created a thread for your message. Please continue any relevant discussion in this thread. You can rename this thread using /title <new title> If this is a technical question that others may benefit from, considering also asking it on Stackoverflow: https://stackoverflow.com/questions/ask?tags=onflow-cadence
Vishal | Flow
Vishal | FlowOP•9mo ago
Line 191 mentions a deprecation notice https://www.flowdiver.io/contract/A.49a7cda3a1eecc29.NFTCatalog?tab=deployments I found a script that uses the old function call..and am trying to figure out how to use the new call..specifically, how to get hold of the catalog within the function that is passed in Old script - import MetadataViews from 0x1d7e57aa55817448 import NFTCatalog from 0x49a7cda3a1eecc29 import NFTRetrieval from 0x49a7cda3a1eecc29 pub fun main(ownerAddress: Address) : {String : [UInt64]} { let catalog = NFTCatalog.getCatalog() // Want to replace this call as per deprecation notice let account = getAuthAccount(ownerAddress) let items : {String : [UInt64]} = {} for key in catalog.keys { let value = catalog[key]! let tempPathStr = "catalogIDs".concat(key) if let tempPublicPath = PublicPath(identifier: tempPathStr) { account.link<&{MetadataViews.ResolverCollection}>( tempPublicPath, target: value.collectionData.storagePath ) let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) if !collectionCap.check() { continue } let ids = NFTRetrieval.getNFTIDsFromCap(collectionIdentifier : key, collectionCap : collectionCap) if ids.length > 0 { items[key] = ids } } } return items } New script - pub fun main(ownerAddress: Address) : {String : [UInt64]} { let account = getAuthAccount(ownerAddress) let items : {String : [UInt64]} = {} NFTCatalog.forEachCatalogKey(fun (key: String): Bool { // but how do I get hold of the catalog here? to do a catalog[key] nvm - found all my answers here 🙂 https://github.com/onflow/nft-catalog#using-the-catalog-for-marketplaces-and-other-nft-applications
Want results from more Discord servers?
Add your server