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 Website.

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:

{
  "success": true,
  "message": "Marketplace stats fetched successfully",
  "result": {
    "total_sales": 1, // total no. of NFTs sold 
    "sales_volume": 0.1, // total value worth of NFTs sold
    "total_sellers": 1, // no. of unique sellers in the marketplace
    "total_listings": 2, // no. of NFTs listed
    "listed_volume": 0.2 // total value worth of NFTs listed for sale
  }
}

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

GET https://api.shyft.to/sol/v1/marketplace/treasury_balance?network=devnet&marketplace_address=54K5BTMj8ynktzEeaD1iGhAJsCN2svBKmD1fTQTonbBB

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:

{
    "success": true,
    "message": "treasury balance fetched successfully",
    "result": {
        "amount": 1.56,
        "symbol": "SOL"
    }
}

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:

POST https://api.shyft.to/sol/v1/marketplace/withdraw_fee

The Request Header

{
    "Content_Type": "application/json",
    "x-api-key": "YOUR SHYFT API KEY"
}

The Request Parameters (body)

{
  "network": "devnet",
  "marketplace_address": "5p4Bua5tSsSo1RJ94H1w5DiMSPfWcvMvnMVjPpZ6sJUb",
  "amount": 1,
  "authority_wallet": "Eb3ykuiCtvGcqs4XRCASThFf4EUxrL7k3TZsytWkXTBe"
}

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.

Here is a sample response from the API.

{
    "success": true,
    "message": "Fee withdrawal transaction created successfully",
    "result": {
        "from": "CRA4Qd6H4tisWLCENT7pzaRbURcKwZTToDnGHTezRxBG",
        "to": "EUUT8hfgak2YKcW41HoNWeiTuARv33fwRPn416enRxsR",
        "amount": 1,
        "encoded_transaction": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAQIyeELoVlWCYLzz5fir3Nbcqf9Gx2d8RF9cFc+TSeDElFHfKaEpfrS4sxhTff+YHEOX/lQ1QNNWX1H25zIx6SthKmgvQV3nsD/OO7+XxS/J6DzL6yyUKOy+3PQUD+AOLz/yDGmfLg6xNhu9NDmNtXnhx0ZrxBqwdoCsUBaP+p1ChgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADNSe+qQqT3GAvPsRINdaFIq6fOJtX7xNNqyXom6lJf9CmWThjy6RhVk6uQTc3IVRusBUckwgna71K0qHDpCEHsG3fbh12Whk9nL4UbO63msHLSF7V9bN5E6jPWFfv8AqaMKy0fh8oHtamtDl4kF1O2PHC5CeU8uf1uHup73YnvsAQYHBQADAgEHBBAApFZMOEgMqgDKmjsAAAAA"
    }
}

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:

GET https://api.shyft.to/sol/v1/marketplace/buy_history?network=devnet&marketplace_address=5p4Bua5tSsSo1RJ94H1w5DiMSPfWcvMvnMVjPpZ6sJUb&buyer_address=AaYFExyZuMasdszjimKyQBAH1yfA9sKTxSzBc6Nr5X4s

The Request Header

{
    "Content_Type": "application/json",
    "x-api-key": "YOUR SHYFT API KEY"
}

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.

{
  "success": true,
  "message": "Order history fetched successfully",
  "result": [
    {
      "network": "devnet",
      "marketplace_address": "7b2dSy4F26A6WweKgdmXzyi5FhhN5AqhuXAQHYcaXfqW",
      "seller_address": "PEsSDkh5FsCDWeJfqLsKx7zC9ijkqKpCuYQxh8FYBiTJe",
      "price": 1,
      "nft_address": "DcxcgowdRg2bXasdadsaeppYY7GFquasdadwTVz3L",
      "buyer_address": "AaYFExyZuMasdszjimKyQBAH1yfA9sKTxSzBc6Nr5X4s",
      "created_at": "2022-08-17T04:36:16.094Z"
    },
    {
      "network": "devnet",
      "marketplace_address": "7b2dSy4F26A6WweKgdmXzyi5FhhN5AqhuXAQHYcaXfqW",
      "seller_address": "GE4kh5FsCDasdadx7zC9ijkqKpCuYQxh8FYBiTJe",
      "price": 1,
      "nft_address": "AfsdsaowdRg2basdadeppYY7GFquNhbZ5RwTVz3L",
      "buyer_address": "AaYFExyZuMasdszjimKyQBAH1yfA9sKTxSzBc6Nr5X4s",
      "created_at": "2022-08-15T02:31:16.096Z"
    }
  ]
}

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.

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 here.

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

Resources

SHYFT API Documentation

Shyft Website

Get API Key

GitHub

Tool for Signing Transaction on Solana

Join our Discord.

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