Build your first NFT marketplace

This is about NFT marketplaces and how you can build them with SHYFT Marketplace APIs

Welcome to the first episode of the marketplace series.

If you have already gone through this part of the series, Click here for the next part of the series.

Why choose SHYFT?

NFT Marketplace, like a regular marketplace, is a digital platform where we can store, list, and sell Non-Fungible Tokens (or NFTs). Users need a Crypto Wallet to connect to the marketplace, trade, and showcase their most desirable NFTs. These tokens can be of any type, such as pictures, Digital Art, Music, writings, or anything else, and generally, they are available for trading, purchase, or even auctions starting at a certain price.

SHYFT’s Marketplace API holds the upper hand over other regular marketplace APIs in certain aspects:

  • No backend infrastructure is needed: A few API calls in the front end are good to take your product to market and scale without hassle.

  • Set any currency: Choose SOL or any SPL token(USDC, mSol, RAY, or create your own) as the marketplace currency.

  • Super fast reads for better UX: Cached NFTs and metadata allow lightning-fast reads, ensuring your users a smooth experience.

  • Marketplace Stats: Access your marketplace’s detailed stats in real-time, manually tracking sales is no longer required.

  • Auctions and Bidding: Instantly enable on-chain auctions and bidding on NFTs.

  • Royalty Distribution: Our APIs honor the original creators by making sure they get their royalty.

This is a series of Tutorial Blogs that will show how you can create and set up a simple NFT marketplace within minutes using SHYFT APIs. You can also check out our sample project on NFTs and marketplace which we have built using SHYFT’s Marketplace APIs.

Read The SHYFT Marketplace APIs Documentation here.

Common Terms used while using SHYFT Marketplace APIs

Shyft creates escrow-less marketplaces, where the NFTs remain in a user's wallet until the sale is complete. There are a few important concepts to understand and efficiently use these APIs.

authority: The account which has the permission to update the marketplace properties and execute a withdrawal from the marketplace treasury. By default, the marketplace creator is the authority.

Creator: The account which pays the gas fee for executing the marketplace creation instruction.

Fee Recipient: The destination account address, that will receive the funds whenever they are withdrawn from the marketplace treasury.

Fee Payer: An account that is used to pay for Solana fees for the seller and buyer if the marketplace chooses to execute the sale in the background.

Transaction Fee: The percentage of every sales transaction amount that will be deposited in the marketplace treasury. By default, all the Shyft-created marketplaces have a 2% transaction fee.

Treasury: The marketplace treasury is an on-chain account where all the transaction fee received by the marketplace gets deposited and remains there until withdrawn.

Currency Address: The SPL token that is used as the currency in the marketplace. SOL is the default currency, if not provided while marketplace setup.

Currency Symbol: The on-chain symbol of the SPL token currency of the marketplace.

Listing: Before an NFT can be sold and bought by a user, it has to be listed for sale in the marketplace at a certain price. Listing represents an NFT on sale.

List State: An on-chain address where all the transactions that happen on an NFT listing are stored. This is unique for each NFT listing created. Generated at the time of list creation.

xxx_wallet: In the following doc, there are API input parameters ending with the wallet. These are essentially the accounts that pay the gas fee of the API's operation.

Pre-requisites for this Tutorial.

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 SHYFT website. Just signup with your email id here and you can get it for free.

A phantom Wallet browser extension

We will need the Phantom wallet browser extension, you can download it from the link below.

Once done, set up your Phantom wallet account. On-screen tips are available which will guide you to set up and get started. You can also find a detailed guide related to this here.

Setting up a marketplace

Once you have collected your own x-api-key from the SHYFT Website, we can start creating an NFT marketplace using SHYFT APIs.

The API Endpoint and its parameters

The API endpoint for the create request

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

The Request Header

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

The Request Parameters (body)

{
    "network": "devnet",
    "creator_wallet": "EijtaNNHqqaPmWwAmRiCR1TC6gSPnqkoodQd2BLFpA8T",
    "authority_address": "EijtaNNHqqaPmWwAmUi8f1TC6RiCRoodQd2BLFpA8T",
    "currency_address": "3S8nRiCRhewv8jdy54xqxMt2GekpCDFVF3zkWAF2EThf",
    "fee_payer": "EijtaNNHqqaPmWwAmUi8f1TC6gSPnq123dQd2BLFpA8T",
    "fee_recipient": "EijtaNNHqqaPmWwasd8f1TC6gSPnqkoodQd2BLFpA8T",
    "transaction_fee": 10
}

Details of the Parameters Used

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

  2. creator_wallet (Required Parameter) : The Wallet Address used for creating the marketplace. This wallet will be responsible for paying the gas fees during the create marketplace transaction.

  3. authority_address : Wallet address for the wallet which will have all the master controls over the marketplace. This wallet will have access to all the critical operations of the marketplace such as the authority to update the wallet, withdraw units from the treasury, etc. By default i.e. if left blank, the value of this field will be the creator_wallet.

  4. currency_address : The address of the SPL Token which will be used for the marketplace transaction. If no token address is provided, the default value for this field is SOL.

  5. fee_payer : An account that is used to pay for Solana fees for the seller and buyer if the marketplace chooses to execute the sale in the background. By default, it is the value of the creator address.

  6. fee_recipient : The destination wallet address that will receive the funds whenever they are withdrawn from the marketplace treasury.

  7. transaction_fee : This is the percentage, not a number. This indicates the percentage of the sale amount for each sale transaction, which is deposited in the marketplace treasury. By default, its value is 2%.

We can directly execute this API call using JavaScript or any programming language, or we can create and use a form to collect all the values required for executing this API call. Once this API request is successfully executed, we should have a response that should look somewhat like this.

{
  "success": true,
  "message": "Create marketplace transaction generated successfully",
  "result": {
    "network": "testnet",
    "address": "5p4Bua5tSsSoasdRJ95I1w5DiMSPfWcvMvnMVjPpZ6sJUb",
    "treasury_address": "EUUT8hasdadYKcW41HoNWeiTuARv33fwRPn416enRxsR",
    "fee_payer": "EijtaNNHqqaPmWwAmUi8f1TC6RiCRoodQd2BLFpA8T",
    "fee_recipient": "Eb3ykuiCtvGcqasdRCASThFf4EUxrL7k3TZsytWkXTBe",
    "fee_recipient_account": "Hssq28jWr8FTxwUwundqpvxbYtrLZEa6vPFaQiVUKDMf",
    "currency_address": "3S8nRiCRhewv8jdy54xqxMt2GekpCDFVF3zkWAF2EThf",
    "currency_symbol": "SFC",
    "creator": "EijtaNNHqqaPmWwAmUi8f1TC6RiCRoodQd2BLFpA8T",
    "transaction_fee": 10,
    "authority": "EijtaNNHqqaPmWwAmUi8f1TC6RiCRoodQd2BLFpA8T",
    "encoded_transaction": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAgOeIxYh8iwxnr/Z8an9vWgkVkEuiJMj33J4B142NukBHgPrdnS7vUWJWdlVRJkN9IyKmqznjwdiF1CUVP5Yqgf4x9LP9K1v1msPEvvdrPLdStXobeMW9+Q08bSktHrXTZWjA9WxBjAnhHQxRwIoIJgxIEKxES6EhU3CearoA/FNkDL2Tz8ECwUGHyaWuUik2ukTTolCWNP5F9oXvoxjPoaDPrDgKnSQEpxoc5cQaL4zLOBiNFCrfL6iPx2ikQLDcYeAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABnmECCqlsIMcbFpqlapSWdgN1oYDA1x0VtmheYQvu7gY5QrbBC1iZfe4ecg7aG0QA11Mr10/XZTNaMWT6GlHiojJclj04kifG7PRApFI4NgwtaE5na/xCEBI572Nvp+FnJ4QuhWVYJgvPPl+Kvc1typ/0bHZ3xEX1wVz5NJ4MSUQplk4Y8ukYVZOrkE3NyFUbrAVHJMIJ2u9StKhw6QhB7BqfVFxksXFEhjMlMPUrxf1ja7gibof1E49vZigAAAAAG3fbh12Whk9nL4UbO63msHLSF7V9bN5E6jPWFfv8AqcjicskpGXDJi75LLG/lXL+Mb6GXudnQ8PEzZL7Oz9heAQsNBwAIBAUKAgMBDQYJDA/dQvKf+c6G8f3//+gDAAA="
  }
}

Note: This is a sample response, the actual one may have different values, but the fields will be the same.

Note: One marketplace owner cannot own two marketplaces with the same currency and wallet address.

Once we successfully execute the API call and get the response successfully, we should receive an encoded_transaction in response. Now, this encoded_transaction needs to be signed using the user wallet, or the user's private key.

Learn how to sign encoded transactions here.

or

Use this deployed website to easily sign with a wallet or a private key in your front end:

https://shyft-insider.vercel.app/

Once signed successfully, the NFT marketplace will be created and will be ready to use. You can also modify an existing marketplace using SHYFT APIs if you have the update authority i.e. the authority_address while creating the marketplace is your wallet address.

Updating an existing Marketplace using SHYFT APIs

Only the wallet, which was set as the update authority (authority_address) during the marketplace creation has the authority to update the marketplace. Parameters that can be updated in an existing marketplace:

  • authority_wallet: The wallet id that has the update authority to the marketplace can be updated, by passing in the new authority wallet in the new_authority_wallet field.

  • transaction_fee: The transaction fee (percentage) set for each transaction in the marketplace, can be set to a new value.

  • fee_payer: The existing fee_payer for the marketplace background transaction can be assigned to a new wallet.

  • fee_recipient: The existing fee_recipient for the marketplace can be assigned to a new wallet.

Endpoint for updating an NFT marketplace.

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

Parameters:

{
  "network": "devnet",
  "authority_wallet": "EijtaNNHqqaPmWwAmUi8f1TC6RiCRoodQd2BLFpA8T",
  "marketplace_address": "5p4Bua5tSsSoasdRJ95I1w5DiMSPfWcvMvnMVjPpZ6sJUb",
  "new_authority_address": "54K5BTMj8ynktzEeasdaahAJsCN2svBKmD1fTQTonbBB",
  "transaction_fee": 12,
  "fee_payer": "EijtaNNHqqaPmWwAmUi8f1TC6RiCRoodQd2BLFpA8T",
  "fee_recipient": "EijtaNNHqqaPmWwAmUi8f1TC6RiCRoodQd2BLFpA8T"
}

The parameters are similar to the ones used in the create marketplace API. This API also returns an encoded_transaction similar to the create marketplace API, and the transaction needs to be signed using the user wallet.

So, That's pretty much everything about this blog, which shows us how to create a simple NFT marketplace on the Solana blockchain using SHYFT APIs.

In the next episode, we will see how to list, buy and perform transactions on the marketplace we just created in this episode. Happy Hacking and stay tuned. πŸŽ‰

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