Display user inventories
Estimate time to complete: 20 minutes
Learn how to display user-owned assets in your application.
At the core of all Web3 games is the concept of true asset ownership, so it is critical for games and marketplaces to offer users a complete and up-to-date view of the assets they own. There are a number of ways to do this:
Method | Description |
---|---|
Direct Event Monitoring | Monitor events yourself by connecting to a blockchain RPC and filtering blockchain logs according to your use case. Provides maximum customisability, but you will need to maintain your own infrastructure and invest in scalability and performance. |
Immutable Blockchain Data APIs | Immutable provides a strong set of default APIs for accessing blockchain data which is regularly used by games, optimised for the scale required by mainstream-quality games. |
Third Party Indexer | There are many blockchain data indexers which provide similar functionality. Some of these providers expose REST APIs and others provide Graph-based interefaces for querying. Ensure your chosen indexer supports your chosen blockchain (e.g. Immutable zkEVM). |
The following tutorial assumes you're using Immutable's Blockchain Data APIs.
NFT Inventories
Most Web3 game items such as weapons, powerups and skins are powered by non-fungible tokens (NFTs). Partners can use Immutable's Blockchain Data APIs product to track player inventory changes in their applications by either:
- Loading ownership data directly from Immutable's APIs
- Updating your own inventory backend using webhooks from Immutable
Option 1: Loading ownership data from Immutable's APIs
Immutable provides an endpoint to returns all the NFTs that belong to a particular owner wallet address:
- SDK
- API
import { blockchainData } from '@imtbl/sdk';
import { client } from '../lib';
export async function listNFTsByAccountAddress(
chainName: string,
contractAddress: string,
accountAddress: string,
): Promise<blockchainData.Types.ListNFTsResult> {
return await client.listNFTsByAccountAddress({
chainName,
contractAddress,
accountAddress,
});
};
GET {baseURL}/v1/chains/{chainName}/accounts/{address}/nfts
Polling Immutable's Blockchain Data API is a great way to get additional details regarding an asset or an activity. See the below table for useful endpoints that can be harnessed for the purpose of monitoring updates in players' inventories.
Data Endpoints | Description |
---|---|
Activities | This endpoint provides historical "activities" (e.g. NFT mints, transfers, burns and trades) on Immutable-supported blockchains. No NFT metadata is present in these API responses. |
NFT | This endpoint provides details on NFT assets including metadata. The NFT Owner feature should be used to determine who is the current custodian of a specific NFT. |
Collections | This endpoint provides details on a specific collection including metadata. The collections endpoint provides additional information as to the grouping of each NFT represented within the collection. No NFT ownership information is delivered with this endpoint. |
Option 2: Updating your own inventory backend using webhooks from Immutable
For applications which want to maintain their own asset databases (for performance or customisation), Immutable can also send webhooks whenever an asset's ownership/history or metadata is updated. You can complement these webhooks with synchronous calls to the NFT endpoint for more detail if necessary.
Identify what type of events your application would like to be notified of via a webhooks stream
Immutable's Blockchain Data API can send notifications for various on and off-chain events through a single webhook connection.
Event Group | Event Types | Description |
---|---|---|
Activities | imtbl_zkevm_activity_mint ; imtbl_zkevm_activity_burn ; imtbl_zkevm_activity_trasnfer ; imtbl_zkevm_activity_sale ; imtbl_zkevm_activity_deposit ; imtbl_zkevm_activity_withdrawal | This event provides details on minting (NFT), transferring (NFT), burning (NFT), trading (NFT), withdrawals (ERC20) and deposits (ERC20) on Immutable's zkEVM blockchain. These events are a valuable resource for tracking changes in NFT ownership as they contain details of wallet addresses, facilitating ownership tracking. No metadata is present in these events. |
NFT | nft_updated | This event signals when an NFT is created or modified. It includes token_id to metadata_id mappings, connecting metadata stacks to individual NFTs. When used in conjunction with the metadata_updated event, it provides a comprehensive view of NFTs and their associated metadata within Immutable's ecosystem. No ownership information is contained within this event. |
Metadata | metadata_updated | This event provides details of a metadata stack's attributes, with each stack being defined by a unique metadata_id . This event is triggered when new metadata stacks are created, as well as when existing stacks get updated through the Metadata Refresh service. No ownership information is contained within this event. |
Collections | collection_updated | This event provides details on newly deployed collections as well as collection updates, including metadata attributes. This event provides additional information as to the grouping of each NFT represented within each collection. No NFT ownership information is delivered with this endpoint. |
Trades | trade_created | This event signals when a trade takes place on Immutable's Global Orderbook. The details of the trade are present, including additional fees. It provides trade details, including any additional fees, as well as buyer and seller addresses. For tracking inventory changes, Immutable suggests using activities_sale events unless more specific trade details are required. |
Select filters for each event
Each event mentioned above can be customised with specific filters applied at the event level. This means that different events can have their own unique filters to refine the data stream as needed. For more information on each event's filters, select the links above to learn more about each event.
By default a webhook subscription will return all events from all collections on a specified chain
Request webhooks from your Partner Success representative
Contact your Immutable Partner Success representative to set up your custom webhooks connection.
Develop a webhook endpoint function
To set up your webhook, follow these steps:
- Create a webhook endpoint function to handle the events sent by Immutable via POST.
- Share your webhook's endpoint details with Immutable.
- Accept the subscription invitation sent by Immutable.
- Begin receiving and processing webhooks as they come in.
Webhook Payload Examples
- imtbl_zkevm_activity_mint
- imtbl_zkevm_activity_burn
- imtbl_zkevm_activity_transfer
- imtbl_zkevm_activity_sale
- trade_created
{
"Type": "Notification",
"MessageId": "dca9d68e-f9b0-5b4b-aca7-8b26df34eac6",
"TopicArn": "arn:aws:sns:us-east-2:783421985614:webhook-outbound-sandbox",
"Message": "{\"event_name\":\"imtbl_zkevm_activity_mint\",\"event_id\":\"018b3c3d-a3aa-a4c9-4c16-dc7a2bd7d715\",\"chain\":\"imtbl-zkevm-testnet\",\"data\":{\"id\":\"018b3c3d-a377-8e68-6cab-2e8db249729a\",\"chain\":{\"id\":\"eip155:13472\",\"name\":\"imtbl-zkevm-testnet\"},\"details\":{\"to\":\"0x9c1634bebc88653d2aebf4c14a3031f62092b1d9\",\"asset\":{\"token_id\":\"123123\",\"contract_type\":\"erc721\",\"contract_address\":\"0x43c98025464e9b326be3c3782db5867073b8e78c\"},\"amount\":\"1\"},\"indexed_at\":\"2023-10-17 06:05:54.469511\",\"activity_type\":\"mint\",\"blockchain_metadata\":{\"log_index\":\"0\",\"block_number\":\"2895332\",\"transaction_hash\":\"0xa58996d4250b964799ad62afa1b6d9188df1d60fad339857ccab4388a07212af\",\"transaction_index\":\"0\"}}}",
"Timestamp": "2023-10-17T06:05:56.378Z",
"SignatureVersion": "1",
"Signature": "hYHM9z0H38JA3AYO/guKTRgsxloGLx0vICVLny36gM8vfqjj1i7xzxRioWFTB+OfngE96gG+vmLmGf7W/RWkjf+dn9dKBijAtZ5CTKigkYnhmxNY1CuarAsEAzf2BlpY80fzHx+gaHaLUgaC6/DJ3ZGD1gM8SS4J5JWKWpvf7DAclGyIp8cPHCcsOcT8JBJf1Mu8Z+0sDOIhtsMD04pUn6QGAbZ82z6eG9mn1PbrocPE/8lOk8elmXdvQjVn9+FcLEIEadXG6INooJ5e5EtZuVEKXlVj9tPugwDbm/1nuWWAf2tArjGvHzIWL04IwbBMDj5Bx5cMU7ycPuLoea3ATA==",
"SigningCertURL": "https://sns.us-east-2.amazonaws.com/SimpleNotificationService-01d088a6f77103d0fe307c0069e40ed6.pem",
"UnsubscribeURL": "https://sns.us-east-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-2:783421985614:webhook-outbound-sandbox:b2be3be8-98de-4d84-b9b1-98d95859351d",
"MessageAttributes": {
"chain": {
"Type": "String",
"Value": "imtbl-zkevm-testnet"
},
"collection_address": {
"Type": "String",
"Value": "0x43c98025464e9b326be3c3782db5867073b8e78c"
},
"event": {
"Type": "String",
"Value": "imtbl_zkevm_activity_mint"
}
}
}
{
"Type": "Notification",
"MessageId": "0f07c54b-6012-511f-bcfc-98e346e2ae54",
"TopicArn": "arn:aws:sns:us-east-2:783421985614:webhook-outbound-sandbox",
"Message": "{\"event_name\":\"imtbl_zkevm_activity_burn\",\"event_id\":\"018b3c3f-4f8e-6432-7777-d5ebb3cfcbf8\",\"chain\":\"imtbl-zkevm-testnet\",\"data\":{\"id\":\"018b3c3f-4f68-2cf0-294d-de745ac3c83e\",\"chain\":{\"id\":\"eip155:13472\",\"name\":\"imtbl-zkevm-testnet\"},\"details\":{\"from\":\"0x9c1634bebc88653d2aebf4c14a3031f62092b1d9\",\"asset\":{\"token_id\":\"123123\",\"contract_type\":\"erc721\",\"contract_address\":\"0x43c98025464e9b326be3c3782db5867073b8e78c\"},\"amount\":\"1\"},\"indexed_at\":\"2023-10-17 06:07:43.976969\",\"activity_type\":\"burn\",\"blockchain_metadata\":{\"log_index\":\"0\",\"block_number\":\"2895386\",\"transaction_hash\":\"0x8ae7f0741df92ae9ed2cccb2947159cae0e1c14da14f9ae94aa3221de237db3b\",\"transaction_index\":\"0\"}}}",
"Timestamp": "2023-10-17T06:07:44.425Z",
"SignatureVersion": "1",
"Signature": "qjvZcBDXIybQUVIkOGeiXu62C3Wk7e5RcLtV3K8GeToXDOI7rCq0D0BBp4PATmnengdQ+/9IEll94+iAXdHgdczmd6F5+Y45ejh1u2S4T7j5dyaxzjZMr6kd1ULH3m2+WFqim14jeyPXClIHUMTfqtQxQuNemIy4pYnfnsy/j8JcR46aGcGWe2aIcytc0EqAE4CBnrG6iUwAFqOyVZF5S/9lWARacCm/JDU1mP3JqCBnqzFu8XwGaOAhXafgJAQmVvUo9gsoKV/+EvT8AIeLv0B8QbDtpR13IStdWIzJzYYD/OiExPquDlcQAbVfWBcMe2bcGD77QDeOky3ZAeWWnA==",
"SigningCertURL": "https://sns.us-east-2.amazonaws.com/SimpleNotificationService-01d088a6f77103d0fe307c0069e40ed6.pem",
"UnsubscribeURL": "https://sns.us-east-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-2:783421985614:webhook-outbound-sandbox:b2be3be8-98de-4d84-b9b1-98d95859351d",
"MessageAttributes": {
"chain": {
"Type": "String",
"Value": "imtbl-zkevm-testnet"
},
"collection_address": {
"Type": "String",
"Value": "0x43c98025464e9b326be3c3782db5867073b8e78c"
},
"event": {
"Type": "String",
"Value": "imtbl_zkevm_activity_burn"
}
}
}
{
"Type": "Notification",
"MessageId": "55a0d5cd-56e3-5075-b11a-8865634a8d5d",
"TopicArn": "arn:aws:sns:us-east-2:783421985614:webhook-outbound-sandbox",
"Message": "{\"event_name\":\"imtbl_zkevm_activity_transfer\",\"event_id\":\"018b3c78-d474-e207-6b19-4c12913db24a\",\"chain\":\"imtbl-zkevm-testnet\",\"data\":{\"id\":\"018b3c78-d466-ec11-5141-d8f0df508b04\",\"chain\":{\"id\":\"eip155:13472\",\"name\":\"imtbl-zkevm-testnet\"},\"details\":{\"to\":\"0x452e19c31112972fcb28f0b064f008d7206dc5e0\",\"from\":\"0xc606830d8341bc9f5f5dd7615e9313d2655b505d\",\"asset\":{\"token_id\":\"1\",\"contract_type\":\"erc721\",\"contract_address\":\"0x202662966b8668f59438db640edc3e8f730d4723\"},\"amount\":\"1\"},\"indexed_at\":\"2023-10-17 07:10:33.575293\",\"activity_type\":\"transfer\",\"blockchain_metadata\":{\"log_index\":\"3\",\"block_number\":\"2897247\",\"transaction_hash\":\"0xc2073dedbdc307777d871b1ea8ffcdf1944ef2e352cbcbe6bce6e7adef7f9146\",\"transaction_index\":\"0\"}}}",
"Timestamp": "2023-10-17T07:10:33.800Z",
"SignatureVersion": "1",
"Signature": "X+YiHeGur1hqxAMY8/vtURj1rUUvRRIdsLSh1O3N0PjVNznWRkOOmf8SXgeb87XAS5L9NWjFpw+r69Rfd2cIBajXHSeA7WUQyOqVUcXrYfF2IX6kQ3isrX7YHbVgg5I0ADRr7ujG4QlEaYObEPZNbgOsB4lsB5Azc6SO1C+pK9VZVQZ+WzYP94z9RRYRX8Hp9Kfe+SHzUZGYuMVCO1cvMTIuiI/wolFSm35Gy75T4OlTRHx+BCIorifGMS/tqZF9HWdsy0TyBhtBgkDxIF2wAN7lGZIRPyHeZWvgUX69KJBDZskj6X4xXL8M0ChtQ8npk3avMU5ELPn97X8zN5/SJQ==",
"SigningCertURL": "https://sns.us-east-2.amazonaws.com/SimpleNotificationService-01d088a6f77103d0fe307c0069e40ed6.pem",
"UnsubscribeURL": "https://sns.us-east-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-2:783421985614:webhook-outbound-sandbox:b2be3be8-98de-4d84-b9b1-98d95859351d",
"MessageAttributes": {
"chain": {
"Type": "String",
"Value": "imtbl-zkevm-testnet"
},
"collection_address": {
"Type": "String",
"Value": "0x202662966b8668f59438db640edc3e8f730d4723"
},
"event": {
"Type": "String",
"Value": "imtbl_zkevm_activity_transfer"
}
}
}
{
"Type": "Notification",
"MessageId": "5ce3ddd1-a77b-52e2-94e0-807992d7b22c",
"TopicArn": "arn:aws:sns:us-east-2:783421985614:webhook-outbound-sandbox",
"Message": "{\"event_name\":\"imtbl_zkevm_activity_sale\",\"event_id\":\"018b3c78-ddd6-3d41-09e0-04d5f272ef72\",\"chain\":\"imtbl-zkevm-testnet\",\"data\":{\"id\":\"018b3c78-ddaa-aa9d-27ae-4bdca220e62e\",\"chain\":{\"id\":\"eip155:13472\",\"name\":\"imtbl-zkevm-testnet\"},\"details\":{\"to\":\"0x452e19c31112972fcb28f0b064f008d7206dc5e0\",\"from\":\"0xc606830d8341bc9f5f5dd7615e9313d2655b505d\",\"asset\":[{\"amount\":\"1\",\"token_id\":\"0\",\"contract_type\":\"erc721\",\"contract_address\":\"0x202662966b8668f59438dB640eDC3e8F730D4723\"}],\"payment\":{\"fees\":[{\"amount\":\"1000\",\"fee_type\":\"ROYALTY\",\"recipient\":\"0xc606830d8341bc9f5f5dd7615e9313d2655b505d\"},{\"amount\":\"2000\",\"fee_type\":\"PROTOCOL\",\"recipient\":\"0xc606830d8341bc9f5f5dd7615e9313d2655b505d\"},{\"amount\":\"1\",\"fee_type\":\"MAKER_ECOSYSTEM\",\"recipient\":\"0xc606830d8341bc9f5f5dd7615e9313d2655b505d\"},{\"amount\":\"1\",\"fee_type\":\"TAKER_ECOSYSTEM\",\"recipient\":\"0xc606830d8341bc9f5f5dd7615e9313d2655b505d\"}],\"token\":{\"symbol\":\"IMX\",\"contract_type\":\"\",\"contract_address\":\"\"},\"price_excluding_fees\":\"100000\",\"price_including_fees\":\"103002\"},\"order_id\":\"018b3c78-975e-fc06-f225-6b00a151f6dc\"},\"indexed_at\":\"2023-10-17 07:10:35.977219\",\"activity_type\":\"sale\",\"blockchain_metadata\":{\"log_index\":\"0\",\"block_number\":\"2897247\",\"transaction_hash\":\"0xc2073dedbdc307777d871b1ea8ffcdf1944ef2e352cbcbe6bce6e7adef7f9146\",\"transaction_index\":\"0\"}}}",
"Timestamp": "2023-10-17T07:10:36.292Z",
"SignatureVersion": "1",
"Signature": "Pnb4KFwAsTwXTlOSW7pbsGsIhlgZ1HwqCquvRvsFK5a2hLgOeIM7GmSbnJ8mpWxKXa3Se/ukgVTJkFZIMSw2iIToS8eLZs/YlLbW/FOsoPHYKeyEWtsD9dO8aWPh0pgwsJhk8wSuoXftxqxj6XfWulza5qwIDpsMGFvSqGsw5oEGYejCxdbHpOU9IfGT7h85no71oa+jK/66IPoh0fUGahP4scEmyO3NNI4WB+fBw6ODrTjUEmPwRRT3vG96vK2KPSADH/4ftliz20TdxU7cWMSXGLgImoccjTGT2tKNZvuuSK2cKaejcC2hRwD0s9tFkCXuKWRthS66nxdik2WtNQ==",
"SigningCertURL": "https://sns.us-east-2.amazonaws.com/SimpleNotificationService-01d088a6f77103d0fe307c0069e40ed6.pem",
"UnsubscribeURL": "https://sns.us-east-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-2:783421985614:webhook-outbound-sandbox:b2be3be8-98de-4d84-b9b1-98d95859351d",
"MessageAttributes": {
"chain": {
"Type": "String",
"Value": "imtbl-zkevm-testnet"
},
"collection_address": {
"Type": "String",
"Value": "0x202662966b8668f59438dB640eDC3e8F730D4723"
},
"event": {
"Type": "String",
"Value": "imtbl_zkevm_activity_sale"
}
}
}
{
"event_name": "trade_created",
"event_id": "018b3ac9-f0d1-a626-1d3e-aebad25e55f3",
"chain": "imtbl-zkevm-testnet",
"data": {
"id": "018b3ac9-f0ce-a4e2-14d3-2360733e7f71",
"tx_hash": "0x78feeab1f1d5d7cb3004d8c077a770a59f558435a497add4f9002cef66c822d0",
"chain_id": "eip155:13472",
"order_id": "018b3ac9-a2c3-c153-8c18-01902b663abb",
"buy_items": [
{
"amount": "1000000",
"item_type": "NATIVE",
"contract_address": ""
}
],
"buyer_fees": [
{
"amount": "10000",
"fee_type": "ROYALTY",
"recipient": "0xc606830d8341bc9f5f5dd7615e9313d2655b505d"
},
{
"amount": "20000",
"fee_type": "PROTOCOL",
"recipient": "0xc606830d8341bc9f5f5dd7615e9313d2655b505d"
},
{
"amount": "1",
"fee_type": "MAKER_ECOSYSTEM",
"recipient": "0xc606830d8341bc9f5f5dd7615e9313d2655b505d"
},
{
"amount": "1",
"fee_type": "TAKER_ECOSYSTEM",
"recipient": "0x71C7656EC7ab88b098defB751B7401B5f6d8976F"
}
],
"sell_items": [
{
"amount": "1",
"token_id": "0",
"item_type": "ERC721",
"contract_address": "0xFdEE4926d1A7B01Cc1B8D086FaF0B2194c99aCc8"
}
],
"block_number": "2883316",
"buyer_address": "0x452e19c31112972fcb28f0b064f008d7206dc5e0",
"seller_address": "0xc606830d8341bc9f5f5dd7615e9313d2655b505d",
"tx_index_in_block": "0",
"log_index_in_block": "0"
}
}