Marketplace Stats, Treasury, and other tasks

Get marketplace stats, check and withdraw treasury balance.

In our previous tutorials about SHYFT's Marketplace APIs, we have seen how we can create and set up a marketplace using custom tokens, Listing NFTs in a marketplace, buying NFTs from a marketplace, and getting active listings from a marketplace. However, SHYFT Marketplace APIs offer a lot more services for having more control and easier management of the marketplace. Let us explore a few of the services which SHYFT's Marketplace APIs have to offer.

This tutorial is a part of a series, please make sure you have gone through the previous parts here

Getting marketplace statistics

SHYFT provides an out-of-the-box stats API for fetching all the relevant marketplace statistics in one call. This removes the requirement of maintaining the marketplace statistics manually using a database, saves time and resources, and makes integration with the front end really easy.

The API endpoint for getting marketplace statistics

GET https://api.shyft.to/sol/v1/marketplace/stats?network=devnet&marketplace_address=54K5BTMj8ynktzEeaD1iGhAJsCN2svBKmD1fTQTonbBB&start_date=2022-09-02&end_date=2022-09-06

Details of the parameter used

Header

  1. x-api-key : The x-api-key is a parameter that is required to use SHYFT APIs. It is used by SHYFT for authorization purposes. You can get your x-api-key for free from the SHYFT Websitearrow-up-right.

Parameters

  1. network (required parameter) : Selects the Solana blockchain network instance, which can be devnet,testnet or mainnet-beta.

  2. marketplace_address (required parameter) : Address of the marketplace whose detailed statistics we want to fetch. In our case, this will be the marketplace we created two tutorials back.

  3. start_date : This field accepts the date as an input in yyyy-mm-dd format. This acts as a filter for fetching all the statistics of a marketplace after a specified date. If empty, returns all the statistics since the day the marketplace was created.

  4. end_date : This field accepts the date as an input in yyyy-mm-dd format. This acts as a filter for fetching all the statistics of a marketplace up to a specified date. If empty, returns all the statistics up to a day before the current date.

start_date and end_date are both optional parameters and they can be used together to fetch statistics between the dates.

Response on successful execution:

Let's see what information we receive from SHYFT's stats API.

  1. total_sales : This field indicates the total number of NFTs sold in the marketplace.

  2. sales_volume : This field indicates the total amount (in marketplace currency) of sales that has taken place in the marketplace.

  3. total_sellers : This field indicates the number of unique sellers in the marketplace.

  4. total_listings : This field indicates the total number of NFTs listed in the marketplace.

  5. listed_volume : This field indicates the total value (in marketplace currency) of listed NFTs in the marketplace.

Getting the marketplaceโ€™s treasury balance

Whenever an NFT is sold from the marketplace, a small percentage of the cost of the NFT is added to the marketplace treasury. This percentage is set by the marketplace creator when the marketplace is created (by default it is 2%). Let's see how you can check the current marketplace treasury balance.

API for checking the marketplace treasury balance

Details of the parameters used:

  1. network : Selects the Solana blockchain network instance, which can be devnet,testnet or mainnet-beta.

  2. marketplace_address : Address of the marketplace whose treasury balance we are attempting to fetch.

Response:

The result field should contain the amount which is the treasury_balance and the currency symbol for the marketplace. Now, let's see how we can withdraw this balance from the marketplace treasury.

Withdraw money from the marketplace treasury

We have learned how we can view (or fetch) our marketplace treasury balance. Now letโ€™s see how we can withdraw money from our marketplace treasury. Please note that only the wallet which was set as the fee_recipient during marketplace creation has the authority to withdraw money from the marketplace treasury.

API for withdrawing fees from the marketplace treasury:

The Request Header

The Request Parameters (body)

Details of the parameters used:

  1. network : Selects the Solana blockchain network instance, which can be devnet,testnet or mainnet-beta.

  2. marketplace_address : Address of the marketplace from which we want to withdraw the treasury balance from.

  3. amount : The amount of treasury balance that we want to withdraw, this should not be greater than the available balance.

  4. authority_wallet : The wallet which has the authority to withdraw fees from the marketplace. This is set when the marketplace is created.

Once the request has been successfully executed, the response received should contain an encoded_transaction which needs to be signed using the usersโ€™ wallet, in this case, the authority_wallet. Find out how to sign transactions on Solana here.arrow-up-right

Here is a sample response from the API.

Getting a walletโ€™s purchase history

Manually tracking and filtering the purchases of one particular buyer may be troublesome, especially when there is a large volume of marketplace data available. But don't worry, SHYFT has you covered. SHYFT provides its users with an API that can fetch the entire purchase history of one particular user in just one call.

API for fetching the purchase history of one particular user:

The Request Header

Details of the Request Parameters

  1. network : Selects the Solana blockchain network instance, can be devnet,testnet or mainnet-beta.

  2. marketplace_address : Address of the marketplace from which they purchased the NFTs.

  3. buyer_address : Wallet Address of the buyer whose order history we are attempting to fetch.

Once successfully executed, the response will return a list containing details of all the transactions done by that particular user. Here is a sample response.

These are some of the many operations you can do with SHYFT APIs. There are a lot more things you can do with SHYFT's Marketplace APIs, check out the full list of marketplace APIs over here.arrow-up-right

Please note that all responses shown in this series are sample responses and not real data. Actual values may differ, but the field names will be the same.

Enjoyed this tutorial series? Feel free to check out our other tutorials on

So, thatโ€™s pretty much all about this series, feel free to check out our marketplace sample project which we have built using SHYFT APIs herearrow-up-right.

Sample NFT Marketplace Built with SHYFT APIs

Stay tuned for more such tutorials and series on SHYFT. Happy Hacking!

Resources

SHYFT API Documentationarrow-up-right

Shyft Websitearrow-up-right

Get API Keyarrow-up-right

GitHubarrow-up-right

Tool for Signing Transaction on Solanaarrow-up-right

Join our Discordarrow-up-right.

If you liked this, you can also read our tutorials on How to get your user's token balances? or How to sign transactions on Solana.

Last updated