List and buy NFTs in the marketplace
Buy and Sell NFTs in your marketplace with Shyf
Last updated
Buy and Sell NFTs in your marketplace with Shyf
Last updated
Trading is an important aspect of any marketplace, be it a conventional one, or a specialized marketplace such as an NFT Marketplace. In this sample project tutorial, we will see, how we can, list, buy, and trade NFTs from the marketplace, which we created in the previous tutorial.
If you have missed our previous tutorial, you can find it , make sure you set up a marketplace using SHYFT APIs before you continue on this tutorial.
If you have already gone through this tutorial, you can find the next tutorial for this series .
x-api-key
is an authentication parameter, which gives you access to SHYFT APIs. You can get your own API Key from the . Just signup with your email id here and you can get it for free.
SHYFT provides an entire set of marketplace APIs for performing all possible operations on an NFT Marketplace.
The API endpoint for listing an NFT on the marketplace
The Request Header
The Request Parameters (body)
Header
Body (All are required parameters)
network: Selects the Solana blockchain network instance, can be devnet
,testnet
or mainnet-beta
.
marketplace_address: Address of the marketplace in which the NFT will be listed. In our case, this will be the marketplace_address of the marketplace we created in the previous tutorial.
nft_address: Token address of the NFT to be listed on the marketplace.
price: Price of the NFT at which it will be listed on the marketplace. The currency will be the marketplace currency.
seller_wallet: Wallet address of the wallet from which the NFT will be listed, i.e. wallet address of the wallet.
Once successfully signed, The NFT will be listed for sale on the Marketplace. Once listed, we can also unlist the NFT from the marketplace so that it is no longer available for sale in the marketplace if needed. SHYFT also provides an API for this purpose.
API for unlisting an already listed NFT from the marketplace.
Parameters :
Now, let's see how we can view all the listings of a particular marketplace.
One of the important functionalities of an NFT Marketplace is showcasing all the listed NFTs so that users have a visual input of the token before they proceed to buy. Also, there is no convenient way to understand, if an NFT has been successfully listed or not unless we are able to view it in active_listings
. This is where getting all listings finds its application. Almost all marketplace UIs have a view that displays a list of all the NFTs available for purchase.
Let’s see how we can do that using SHYFT APIs. The API endpoint for getting all the listed NFTs in a marketplace
The Request Header
The Request Parameters
Here, network
is the Solana blockchain network instance, and marketplace_address
is the address of the marketplace whose active NFTs we will list. On successful execution, the response should return a list of all NFTs currently active on the marketplace. The term "currently active" or "active_listings" refers to the NFTs on the marketplace which have been listed and not yet been sold. On successful execution, the response received should look something like this.
The result
field in the response is an array that contains a list of all the currently listed NFTs in the marketplace.
The API endpoint for buying an NFT from the marketplace
The Request Header
The Request Parameters (body)
Header
Body (All are required parameters)
network : Selects the Solana blockchain network instance, which can be devnet
,testnet
or mainnet-beta
.
buyer_wallet : Wallet address of the wallet from which the NFT will be bought from the marketplace. The price of the NFT and the gas fees for the buy transaction will be deducted from this wallet. Please note that this cannot be the same as the seller_address. Also, the marketplace creator cannot buy NFTs from the marketplace.
seller_address : Wallet address of the wallet from which the NFT will be bought. Once the buy is successful, the NFT will be removed from this wallet and the price at which the NFT was listed will be credited here, minus the marketplace transaction fees.
marketplace_address : Address of the marketplace from which the NFT will be bought from. In our case, this will be the marketplace_address of the marketplace we created in the previous tutorial.
price : Price of the NFT at which the NFT was listed on the marketplace. The currency is the marketplace currency.
nft_address : Token address of the NFT that we are attempting to buy from the marketplace.
So, that's pretty much all about this tutorial about listing and buying items from the NFT marketplace using SHYFT APIs. So far, we have seen how we can set up an NFT marketplace with ease, Trade NFTs, and list all active items to a marketplace using SHYFT APIs.
In the next and final episode of this series, we will be fetching marketplace stats and treasury balance.
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 own x-api-key
for free from the .
We can directly execute this API call using JavaScript or any programming language, or we can use SHYFT's readAll
API to fetch a list of all NFTs of our own wallet and use the NFT address from there to list to the marketplace. Wondering how to list all NFTs from your wallet using SHYFTs readAll
API, read it . Once this API request is successfully executed, we will have a response that should look somewhat like this.
If successfully executed, the response should contain the encoded_transaction
which we will have to sign in order to complete this transaction successfully. This encoded_transaction
can be signed using the user wallet, or the user's private key. . Shyft provides a special package that provides the functionality to sign transactions in two ways, using the wallet via the frontend, or using the private key from the backend. Read our blog on How to sign transactions on Solana .
The parameters are similar to that of the list API, seller_wallet
and seller_address
are the same parameters. This API also returns anencoded_transaction
, similar to the list API, which needs to be signed using the user wallet.
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 own x-api-key
for free from the .
If all the parameters are correct and the request is successfully executed, the response should contain an encoded_transaction
, which needs to be signed using the user wallet or using user's private key. Read more about signing transactions on Solana
Join our
If you liked this, you can also read our tutorials on or .