You can also easily call Collections based on Category and Version reading events:
//The Eth Item Factory has 4 different events, raised when a new Collection is createdvar ethItemFactoryEventsByVersionAndABIValues = {"NewNativeCreated(uint256,uint256,uint256,address)":"NativeABI","NewWrappedERC1155Created(uint256,uint256,uint256,address)":"W1155ABI","NewWrappedERC721Created(uint256,uint256,uint256,address)":"W721ABI","NewWrappedERC20Created(uint256,uint256,uint256,address)":"W20ABI"};
---address ethItemAddress : the address of the Collection created by the Factory
You can choose of course to receive the Collections of all Categories or just the ones you're interested in by removing the irrelevant events in the ethItemFactoryEventsByVersionAndABIValues object above
//Let's convert plain events in keccak256 topics so they can be used for the web3.eth.getPastLogs callvar ethItemFactoryTopicsAndCollectionABIValues = {};Object.entries(ethItemFactoryEventsByVersionAndABIValues).forEach(it => ethItemFactoryTopicsAndCollectionABIValues[web3.utils.sha3(it[0])] = it[1]);
//First argument of the topics array is an array of three hash elements. This means that first log topic can be one of the passed arguments (like the "OR" operator in Web2 DB queries)
var topics = [Object.keys(ethItemFactoryTopicsAndCollectionABIValues)];//Now you can customize the query as you wish, e.g.://All the Collections we want must follow the first version of the EthItem Token Standardtopics.push(web3.eth.abi.encodeParameter('uint256',1));//No matter what is the version of the Interoperable Interface Modeltopics.push([]);//All the Collections must be generated by their respective models, but only for version 2 or 5topics.push([web3.eth.abi.encodeParameter('uint256',2),web3.eth.abi.encodeParameter('uint256',5)]);//Call the blockchain.//Of course this is a generic-purpose code, it can be more efficient by using just the topics you need (e.g. give me only the Wrapped ERC721 Collections) or use from/to block tranches.
var logs =awaitweb3.eth.getPastLogs({ address : factoryAddresses, topics});//Navigate the logs to obtain info about collectionsfor (var log of logs) {//Retrieve the correct ABI using the first log topic through the key/value map previously madevar collectionABIValue = ethItemFactoryTopicsAndCollectionABIValues[log.topics[0]];//As already said, last topic param is che Collection addressvar collectionAddress =web3.eth.abi.decodeParameter("address",log.topics[log.topics.length-1]);//Make a checksum address for eventual off-chain research purposes collectionAddress =web3.utils.toChecksumAddress(collectionAddress);//Grab the correct Collection ABI from the configuration filevar collectionABI = configuration[collectionABIValue];//Extract Collection Category label from the ABI value. Just remove the latest 3 "ABI" characters from the stringvar collectionCategory =collectionABIValue.split("ABI")[0];//Put everything in the allCollections arrayallCollections.push({ address : collectionAddress, category : collectionCategory, contract :newweb3.eth.Contract(collectionABI, collectionAddress) });}//Use all the collections as you wishconsole.table(allCollections.map(it => {return {address :it.address, category :it.category}}));