Frontend Reconstruction
Collection and Items Events
The Item protocol provides two major events regarding Collection and Items creation that can be used in Frontend integrations.
Collection
event
Collection
eventThe first one is the Collection
event:
The Collection
event is currently emitted when a new Collection is created through the createCollection
function:
The address from
is equal to address(0)
because a new Collection is created, the address to
is equal to the new host
address and the collectionId
is equal to the id
of the newly created Collection.
CollectionItem
event
CollectionItem
eventThe second one is the CollectionItem
event:
The CollectionItem
event is currently emitted when:
New Items are created through the
mintItems
functionNew quantity of a previously created Item is minted
When Items are created together with the Collection using the
createCollection
function
Multiple Items can be created in a single transaction, so one CollectionItem
event is emitted for each created Item.
The fromCollectionId
is equal to bytes32(0)
because you're creating a new Item in a Collection, the fromCollectionId
represents the id of the Collection in which the Items have been created and the itemId represents the ids of the newly created Items.
If the Items are created together with the Collection using the createCollection
function, both the Collection
and CollectionItem
events are emitted.
Frontend reconstruction
The following code can be used to retrieve all the existing Collection in your frontend, using the Collection
event:
The following code can be used to retrieve all the Collection with a certain host, aka owner, address in you frontend using the Collection
event:
The following code can be used to retrieve all the Items of specific Collection ids in you frontend using the CollectionItems
event:
Display Item decimals
Items have 18 decimals both on Interoperable Interface (ERC20 side) and Main Interface (ERC1155 side), unlike the classic ERC721 and ERC1155 NFT standards which have 0 decimals.
When you show supply and balances of Items you have to take into consideration that Items have 18 decimals.
All you need to do to correctly display the supply/balance of an Item is implement the following code in your frontend: web3.utils.fromWei("1000000000000000000", 'ether')
“1000000000000000000” would be the Item’s supply.
For example, $OS is an Item, and has a supply of roughly 1 million. But, without this precaution, the supply is displayed as much, much more:
The current $OS supply is 1,036,890.000000000000000000.
If you read it from the Main Interface as a normal ERC1155 with 0 decimal places it displays the $OS supply as 1036890422885628366051096 (i.e. without the proper decimals).
If you read it from the Main Interface using the
web3.utils.fromWei
it displays the $OS supply as 1036890000000000000
Last updated