Build Your Own On-Chain Graph Tracker

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 created
var 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"

For every event, the fields are the same:

---uint256 indexed standardVersion

---uint256 indexed interoperableInterfaceModelVersion

---uint256 indexed modelVersion

---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 call
var 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 Standard
topics.push(web3.eth.abi.encodeParameter('uint256', 1));

//No matter what is the version of the Interoperable Interface Model


//All the Collections must be generated by their respective models, but only for version 2 or 5
topics.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 = await web3.eth.getPastLogs({
    address : factoryAddresses,

//Navigate the logs to obtain info about collections
for (var log of logs) {
    //Retrieve the correct ABI using the first log topic through the key/value map previously made
    var collectionABIValue = ethItemFactoryTopicsAndCollectionABIValues[log.topics[0]];

    //As already said, last topic param is che Collection address
    var 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 file
    var collectionABI = configuration[collectionABIValue];

    //Extract Collection Category label from the ABI value. Just remove the latest 3 "ABI" characters from the string
    var collectionCategory = collectionABIValue.split("ABI")[0];

    //Put everything in the allCollections array
        address : collectionAddress,
        category : collectionCategory,
        contract : new web3.eth.Contract(collectionABI, collectionAddress)

//Use all the collections as you wish
console.table( => {return {address : it.address, category : it.category}}));  

Last updated