Shyft
Start BuildingSupportWebsite
  • Welcome
    • πŸ‘‹Introducing Shyft
    • πŸ—οΈStart Building
  • Solana Infrastructure
    • 🚁Shyft RPCs
  • Yellowstone gRPC Network
    • Decoding gRPC Latency
    • ⚑gRPC Docs
      • Introduction
      • Authentication
      • Subscribe Requests
      • FAQ
      • Getting Started
        • Initializing the Yellowstone Client
        • Making a gRPC connection
        • Adding a Reconnection Mechanism
        • πŸ”₯Replaying Slots with Solana yellowstone gRPCs
        • Modifying your Subscribe Request
        • Closing a gRPC Connection
      • Subscribing to Transactions
        • All Transactions of an address
        • Subscribing to all transactions of a Liquidity Pool
        • Subscribing to all transactions of multiple addresses
        • Subscribing to all transactions of a Token
      • Subscribing to Accounts
        • Account Updates for a Program
        • Account Updates for an Address
        • Account updates using memcmp
      • Streaming Blocks & BlocksMeta
        • Streaming Block Updates
        • Subscribing to BlocksMeta
      • Modifying & Unsubscribing
  • Solana defi data
    • DeFI APIs
      • Get Pool By Address
      • Get Pools By Token Pair
      • Get All Pools for a Token
      • Get Liquidity Details of a Pool
  • Callbacks
    • ☎️What are Callbacks?
      • Transaction Callbacks
      • Account Callbacks
    • πŸ“”Callback APIs
      • Response Structure
      • List Callbacks
      • Register callback
      • Remove callback
      • πŸ”₯Pause a callback
      • πŸ”₯Resume a callback
      • Update Callbacks
      • Add Addresses
      • Remove addresses
  • Solana Super Indexers
    • 🌩️GraphQL APIs
      • Getting Started
      • Building Queries
      • Paginating Response
      • Applying Filters
      • Ordering and Sorting Data
    • πŸ“€Case Studies
      • Tensor
        • Get Active Listings of a Wallet
        • Get Active Bids of a Wallet
        • Get Active Listings of a Collection
        • Get all Bids of a Collection
        • Get all Pools of a Margin Account
        • Get all Pools by Owner
      • Raydium
        • Get Pool By Address
        • Get Pools By Token Address
        • Get Pools Created Between Time
        • Get Pool Burn Percentage
        • Get Liquidity Details of a Pool
        • Get Pool and OpenBook Market Info
        • Get Token Supply Percentage In Pool
      • Orca Whirlpool
        • Get Pool by Address
        • Get Pool by Token Address
        • Get Positions for a Pool
        • Get Positions for a Wallet
        • Get Liquidity Details of a Pool
      • Kamino
        • Get Borrow Details of a Wallet
        • Get Deposit Details of a Wallet
        • Get Reserve Details
      • Cross Marketplace Queries
        • Get active listings across marketplaces for a wallet
        • Get listings for a collection across marketplaces
        • Get floor price of a collection
      • Cross Defi Queries
        • Fetch Liquidity Pools for Token
      • Native Staking
        • Get Stakes for a Wallet
        • Get Stakes For Validator
      • Governance/Realms
        • Get DAO Token Owners
        • Get Proposals For Governing Mint
        • Get All Proposals For DAO
        • Get DAO Treasury Info
        • Get All Active Proposals For Wallet
      • Meteora
        • Get All LB Position Pairs
        • Get Position of a User Wallet
        • Get Pool by Token Addresses
        • Get All Deposits for a User
        • Get All Withdraws for a User
        • Get All Fees Claimed by a User
        • Get All User Positions and Deposits for a Pool
        • Get All User Positions and Withdrawals for a Pool
      • Fluxbeam
        • Get Pool by Address
        • Get Pool by Token Addresses
      • Drift
        • Get User account for Delegate
        • Get User accounts based on authority
        • Get User details based on Referrer
        • Get Borrow/Deposit Amount for an User
        • Get PrepPositions for an User Account
        • Getting OrderId and userOrderId
        • Get OpenOrders for a User Account
      • πŸ”₯Pumpswap
        • πŸ”₯Get Pool by Address
        • πŸ”₯Get Pool by Creator Address
        • πŸ”₯Get Pools by Token Addresses
      • Raydium Launchpad
        • Get Bonding Curve Details by Pool Address
        • Get All Pools for a Creator
        • Get Pools by Token Addresses
        • Get Migration details of a Pool
  • Solana APIs
    • API Reference
    • Transactions
      • Parsed Transaction Structure
      • Transaction APIs
        • History
        • Parse Signature
        • Parse Multiple Signatures
        • Send
        • Send Multiple
    • NFT
      • πŸ”₯Create Gasless
      • Create
      • Read All
      • Burn
      • πŸ”₯Burn Multiple NFTs V2
      • Update
      • πŸ”₯Create NFT from Metadata
      • πŸ”₯Read Wallet Nfts
      • πŸ”₯Read Selected NFTs
      • πŸ”₯Get NFT Owners
      • πŸ”₯Update NFT Metadata Uri
      • πŸ”₯Update V2
      • Search
      • Transfer
      • Transfer Multiple NFTs
      • Mint
      • Read
    • Wallet
      • Get Balance
      • Get Token Balance
      • Get All Tokens Balance
      • Get Portfolio
      • Resolve Address
      • Get All Domains
      • Get Stake Accounts
    • Fungible Tokens
      • Create
      • Mint
      • Burn
      • πŸ”₯Update
      • Get Token Info
      • Transfer
      • Airdrop
Powered by GitBook
On this page
  • Pre-requisites for using SHYFT APIs
  • List (sell) an NFT in the marketplace
  • Unlist NFT from the marketplace (Cancel sale)
  • Get all listings of a marketplace
  • Buying NFTs from a marketplace
  • Resources

Was this helpful?

  1. Dev Guides
  2. Solana
  3. Build NFT Marketplace

List and buy NFTs in the marketplace

Buy and Sell NFTs in your marketplace with Shyf

Last updated 2 years ago

Was this helpful?

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 .

Pre-requisites for using SHYFT APIs

Authentication: Getting your Shyft API key

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.

List (sell) an NFT in the marketplace

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

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

The Request Header

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

The Request Parameters (body)

{
  "network": "devnet",
  "marketplace_address": "5p4Bua5tSsSoasdRJ95I1w5DiMSPfWcvMvnMVjPpZ6sJUb",
  "nft_address": "GpLzvmQYcQM3USHasdahoriEzmJLJ8AfKVdLFZRoVBsz",
  "price": 10,
  "seller_wallet": "GE4kh5FsCDWeJfasdasdkqKpCuYQxh8FYBiTJe"
}

Details of the parameters used:

Header

Body (All are required parameters)

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

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

  3. nft_address: Token address of the NFT to be listed on the marketplace.

  4. price: Price of the NFT at which it will be listed on the marketplace. The currency will be the marketplace currency.

  5. seller_wallet: Wallet address of the wallet from which the NFT will be listed, i.e. wallet address of the wallet.

{
  "success": true,
  "message": "Listing transaction created successfully",
  "result": {
    "network": "devnet",
    "marketplace_address": "5p4Bua5tSsSoasdRJ95I1w5DiMSPfWcvMvnMVjPpZ6sJUb",
    "seller_address": "GE4kh5FsCDWeJfasdasdkqKpCuYQxh8FYBiTJe",
    "price": 10,
    "nft_address": "GpLzvmQYcQM3USHasdahoriEzmJLJ8AfKVdLFZRoVBsz",
    "list_state": "G7accWXzKEvzqtA2vG5EZr1JTLpsEMvo6Kpt9sBhT8xq",
    "currency_symbol": "SFC",
    "encoded_transaction": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAkPA+Z8BRyNDL30G+lsh0lwSNNhbnN6HAnoyUtyAiN7Pg8ZTa3UjJFWTbVDHC886jP1qM+vXRbrQyLDeoBN7DPFTuCOy9VpQ/1bFLqVafsssQa0CmDXlG0szCd/vm3xYAjy61NPZoqzotVq1zh3FtGM1AobPdXo4vpihZLb/KSMAlH+aXsh63u97m9Zk1yHYYCbZADBoeziI3rn4oalp/iO+Q2/5soX1jASgm/taWpC+DJTiveCM+DXxaFA4Q7w0ETdAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8R+yeVfMiObnMrg/7ZjH5/Gyx9ewfekqQYjXSofYb/svZPPwQLBQYfJpa5SKTa6RNOiUJY0/kX2he+jGM+hoMCmWThjy6RhVk6uQTc3IVRusBUckwgna71K0qHDpCEHv0JF6XdZMSX7FZQbbAqSYK9EOLzRA1UpKkCwXfh/XVIP2RX2EYRmx3j1oYfbFSMX0y9sE2+mXakJ/DVFgXv4yXBqfVFxh70WY12tQEVf3CwMEkxo8hVnWl27rLXwgAAAAGp9UXGSxcUSGMyUw9SvF/WNruCJuh/UTj29mKAAAAAAbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpY4c4ACg7P/CAYkG8uUdYoIF0PlYmgYiO9+OaxjLkXrICCQwABQsIBwMCBA4GCg0bM+aFpAF/g63+/f8A0O2QLgAAAAEAAAAAAAAACQUBAAYNDAnPayygS97DG/8="
  }
}

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.

Unlist NFT from the marketplace (Cancel sale)

API for unlisting an already listed NFT from the marketplace.

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

Parameters :

{
  "network": "devnet",
  "marketplace_address": "5p4Bua5tSsSoasdRJ95I1w5DiMSPfWcvMvnMVjPpZ6sJUb",
  "list_state": "3S8nfVMFhewv8jdy54xqxMt2GekpCDFVF3zkWAF2EThf",
  "seller_wallet": "GE4kh5FsCDWeJfasdasdkqKpCuYQxh8FYBiTJe"
}

Now, let's see how we can view all the listings of a particular marketplace.

Get all listings of a 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

GET https://api.shyft.to/sol/v1/marketplace/active_listings?network=devnet&marketplace_address=5p4Bua5tSsSoasdRJ95I1w5DiMSPfWcvMvnMVjPpZ6sJUb

The Request Header

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

The Request Parameters

{
  "network": "devnet",
  "marketplace_address": "5p4Bua5tSsSoasdRJ95I1w5DiMSPfWcvMvnMVjPpZ6sJUb"
}

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.

{
  "success": true,
  "message": "Active listing fetched successfully",
  "result": [
    {
      "network": "devnet",
      "marketplace_address": "5p4Bua5tSsSoasdRJ95I1w5DiMSPfWcvMvnMVjPpZ6sJUb",
      "seller_address": "GE4kh5FsCDWeJfasdasdkqKpCuYQxh8FYBiTJe",
      "price": 10,
      "currency_symbol": "SD",
      "nft_address": "GpLzvmQYcQM3USHasdahoriEzmJLJ8AfKVdLFZRoVBsz",
			"nft": {
        "name": "Planet",
        "symbol": "PLA",
        "royalty": 5,
        "image_uri": "<https://nftstorage.link/ipfs/bafybeifa73zza4pff25fyhrjqgkatovwy25ppcqj76rkl7gp2ej74qpupe>",
        "cached_image_uri": "<https://cdn.shyft.to/img/https%253A%252F%252Fnftstorage.link%252Fipfs%252Fbafybeifa73zza4pff25fyhrjqgkatovwy25ppcqj76rkl7gp2ej74qpupe>",
        "metadata_uri": "<https://nftstorage.link/ipfs/bafkreidd7yzhlhokfpdjcujomkc4ntoxcoerdpqz34s3bs763odwux6tpi>",
        "description": "This is a planet NFT.",
        "mint": "GpLzvmQYcQM3USHa133123iEzmJLJ8AfKVdLFZRoVBsz",
        "owner": "5hbm5nSmtNFd12313G9XsC5rWXAREfPMG3Wj8Wxm6MD4",
        "creators": [
          {
            "address": "5hbm5nS4mtswyhWyG9XsC5rWXAREfPMG3Wj8Wxm6MD4",
            "share": 100,
            "verified": 1
          }
        ],
        "attributes": {
          "awesomeness": "100"
        },
        "attributes_array": [
          {
            "trait_type": "awesomeness",
            "value": "100"
          }
        ],
        "files": [],
        "update_authority": "5hbm5nSmtNFdwyhWyG9XsC5rWXAREfPMG3Wj8Wxm6MD4"
      },
      "list_state": "G7accWXzKEvzqtA2vG5EZr1JTLpsEMvo6Kpt9sBhT8xq",
      "created_at": "2022-08-22T17:16:06.000Z",
      "receipt": "FwEG6zTfM4mT9SaCMS61nswuJcfNDLEi2xn7T7gs4qRs"
    },
    {
      "network": "devnet",
      "marketplace_address": "5p4Bua5tSsSoasdRJ95I1w5DiMSPfWcvMvnMVjPpZ6sJUb",
      "seller_address": "GE4kh5FsCDWeJfqLsKx7zC9ijkqKpCuYQxh8FYBiTJe",
      "price": 300,
      "currency_symbol": "SD",
      "nft_address": "5r2rJ37qUGYCqqHzvjBTjMBh4Pu2VD9wSiUnsky8UzYS",
			"nft": {
        "name": "SperCoins",
        "symbol": "Super",
        "royalty": 5,
        "image_uri": "<https://nftstorage.link/ipfs/assdasd3zasdasdkatovwy25ppcqj76rkl7gp2ej74qpupe>",
        "cached_image_uri": "<https://cdn.shyft.to/img/https%253A%252F%252Fnftstorage.link%252Fipfs%252Fasd73zza4pff25fyhrjqgasdads25ppcqj76rkl7gp2ej74qpupe>",
        "metadata_uri": "<https://nftstorage.link/ipfs/bafasdawdsd7yzhlhokfpdjcujomkc4ntoxcoerdpqz34s3bs763odwux6tpi>",
        "description": "This is a planet NFT.",
        "mint": "GpLzvmQYcQM3USHa133123iEzmJLJ8Sgw12KVdLFZRoVBsz",
        "owner": "6yhsamtNFd12313G9XsC5rWXAREfPMG3Wj8Wxm6MD4",
        "creators": [
          {
            "address": "5hbm5nS4mtswyhWyG9XsC5rWXAREfPMG3Wj8Wxm6MD4",
            "share": 100,
            "verified": 1
          }
        ],
        "attributes": {
          "awesomeness": "100"
        },
        "attributes_array": [
          {
            "trait_type": "awesomeness",
            "value": "100"
          }
        ],
        "files": [],
        "update_authority": "5hbm5nSmtNFdwyhWyG9XsC5rWXAREfPMG3Wj8Wxm6MD4"
      },
      "list_state": "8WM1Etk7fWraMshaAgYc6jBBKVAGsPwwRnNWyke9o5yN",
      "created_at": "2022-08-22T17:20:17.000Z",
      "receipt": "D9qHwezut8c7rmLkaGE1h1Yo3fVTp9EKYnLRDFjupyA3"
    }
  ]
}

The result field in the response is an array that contains a list of all the currently listed NFTs in the marketplace.

Buying NFTs from a marketplace

The API endpoint for buying an NFT from the marketplace

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

The Request Header

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

The Request Parameters (body)

{
  "network": "devnet",
  "buyer_wallet": "AaYFExyZuMHbJHzjimK1232H1yfA9sKTxSzBc6Nr5X4s",
  "seller_address": "GE4kh5FsCDWeJfasdasdkqKpCuYQxh8FYBiTJe",
  "marketplace_address": "5p4Bua5tSsSoasdRJ95I1w5DiMSPfWcvMvnMVjPpZ6sJUb",
  "price": 10,
  "nft_address": "GpLzvmQYcQM3USHasdahoriEzmJLJ8AfKVdLFZRoVBsz"
}

Details of the parameters used:

Header

Body (All are required parameters)

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

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

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

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

  5. price : Price of the NFT at which the NFT was listed on the marketplace. The currency is the marketplace currency.

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

Resources

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 .

πŸ“˜
here
here
SHYFT website
SHYFT Website
here
Find out how
here
Find out how?
SHYFT Website
here
SHYFT API Documentation
Shyft Website
Get API Key
GitHub
Tool for Signing Transaction on Solana
Discord
How to get your user's token balances?
How to sign transactions on Solana