SDK contains generated clients based on openapi documentation. This guide will walk you through the process of querying API using SDK.
Prerequisite
Follow our Getting started guide to install needed libraries and instantiate SDK.
Executing queries
Here are some basic examples of how to use APIs to query data. You can find much more methods in the reference: or right in the typescript typings.
//Fetch items by creator
sdk.apis.item.getItemsByCreator({ creator: someAddress })
//Fetch activity (events) by the Item
sdk.apis.activity.getActivitiesByItem({ type: ["TRANSFER"], contract, tokenId })
//etc. Please explore SDK APIs and openAPI docs
NOTE: Our indexer may scan blockchains with a slight delay. If your code depends on API data you should await it until it appears. Here you can find more information about our indexer delay.
//Don't do like that!
const { address, tx } = await sdk.nft.createCollection({...})
//If collection still not indexed you will get error
const collection = await sdk.apis.collection.getCollectionById({collection: address })
console.log('collection name', collection.name)
Wait till data appears. You can wrap fetching data in retry function:
//To do like that
const { address, tx } = await sdk.nft.createCollection({...})
const attempts = 10;
const timeout = 3000;
const collection = await retry(attempts, timeout, async () => {
return sdk.apis.collection.getCollectionById({collection: address })
})
console.log('collection name', collection.name)
Conclusion
Every API endpoint accessible can be used by using code-generated API client from the SDK instance. You can access it using sdk.apis
Full API reference is accessible here.