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
Details of the parameter used
Header
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 yourx-api-key
for free from the SHYFT Website.
Parameters
network (required parameter) : Selects the Solana blockchain network instance, which can be
devnet
,testnet
ormainnet-beta
.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.
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.
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.
total_sales : This field indicates the total number of NFTs sold in the marketplace.
sales_volume : This field indicates the total amount (in marketplace currency) of sales that has taken place in the marketplace.
total_sellers : This field indicates the number of unique sellers in the marketplace.
total_listings : This field indicates the total number of NFTs listed in the marketplace.
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:
network : Selects the Solana blockchain network instance, which can be
devnet
,testnet
ormainnet-beta
.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:
network : Selects the Solana blockchain network instance, which can be
devnet
,testnet
ormainnet-beta
.marketplace_address : Address of the marketplace from which we want to withdraw the treasury balance from.
amount : The amount of treasury balance that we want to withdraw, this should not be greater than the available balance.
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.
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
network : Selects the Solana blockchain network instance, can be
devnet
,testnet
ormainnet-beta
.marketplace_address : Address of the marketplace from which they purchased the NFTs.
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.
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
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