Tatum
Search…
How to create a peer-to-peer NFT marketplace like OpenSea
Open Sea fixed-priced assets listing in 3 API calls.
Peer-to-peer NFT marketplaces like OpenSea allow users to create NFTs with metadata (pictures, videos, songs, 3D art, etc.) and post listings to sell them to one another. OpenSea then takes a percentage of each sale.
If you want to build a backend for your own peer-to-peer NFT marketplace, you’ll definitely want to implement the same functionality.
Creating NFTs has always been super simple with Tatum. But now, you can also create NFT marketplaces and listings using just a few API calls! When the NFT is sold, the creator is automatically paid, the NFT is instantly transferred to the buyer, and you as the owner of the marketplace automatically receive a percentage of the transaction. Everything happens on the blockchain, so you don’t even need to create a complex, application-level backend to run the listings.
With this type of marketplace, your users can create listings to sell ERC-721 or ERC-1155 tokens. These tokens can be purchased with the native assets of the given blockchain (e.g. ETH on Ethereum or MATIC on Polygon) or any ERC-20 token available on your blockchain of choice.
Currently supported blockchains are Ethereum, Celo, Polygon, Binance Smart Chain, and Harmony.ONE.
All smart contracts are available here.
To learn how to sell NFTs for any supported ERC20 token, please check out our Feature Spotlight on the topic:

Deploy your own marketplace

The first step is to create your own marketplace smart contract. This is a one-time operation, and the marketplace you deploy will be used for every listing in your application. In this example, we'll deploy our marketplace on the Polygon network.
Request
Response
1
curl --location --request POST 'https://api-eu1.tatum.io/v3/blockchain/marketplace/listing' \
2
--header 'Content-Type: application/json' \
3
--header 'x-api-key: YOUR_API_KEY' \
4
--data-raw '{
5
"feeRecipient": "0x8cb76aEd9C5e336ef961265c6079C14e9cD3D2eA",
6
"marketplaceFee": 250,
7
"chain": "MATIC",
8
"fromPrivateKey": "0x37b091fc4ce46a56da643f021254612551dbe0944679a6e09cb5724d3085c9ab"
9
}'
Copied!
1
{
2
"txId": "0x9ff62d44abaf65018081a6511c84ca8f89d7575d2a1ea058e93c1b7d57ff1807"
3
}
Copied!
As you can see in the example above, you must enter a value in the "marketplaceFee" field. This is a percentage of the price that will be charged to the buyer when they make a purchase. The value is the percentage charged * 100, so a 2.5% fee is written as 250. This percentage is the same for all sales made on your marketplace.
The address "feeRecipient" field is where the fees will be sent, i.e. your address as the marketplace owner.
The response is a transaction ID from which we can obtain the contract address.

Create a fixed price asset listing

Once the marketplace is ready, you can enable listings for your users. The NFT asset must be present at the address of the seller before they create an NFT listing. The seller can choose the price of the asset, whether they are selling an ERC-721 or ERC-1155 token, and whether they are selling it for ERC-20 tokens or for the native currency of the given blockchain (in our case MATIC).
Every listing must have a unique listingId. This ID identifies the listing and is used for performing other operations.
The following API call will create a fixed-price NFT listing on your marketplace:
Request
Response
1
curl --location --request POST 'https://api-eu1.tatum.io/v3/blockchain/marketplace/listing/sell' \
2
--header 'Content-Type: application/json' \
3
--header 'x-api-key: YOUR_API_KEY' \
4
--data-raw '{
5
"contractAddress": "0x4153B909f55B0Ec43c11e980dF09b853477D9F79",
6
"nftAddress": "0x6d8eae641416b8b79e0fb3a92b17448cfff02b11",
7
"tokenId": "12",
8
"listingId": "1",
9
"isErc721": true,
10
"price": "0.001",
11
"seller": "0x80D8BAc9a6901698b3749Fe336bBd1385C1f98f2",
12
"chain": "MATIC",
13
"fromPrivateKey": "0x37b091fc4ce46a56da643f021254612551dbe0944679a6e09cb5724d3085c9ab"
14
}'
Copied!
1
{
2
"txId": "0x9ff62d44abaf65018081a6511c84ca8f89d7575d2a1ea058e93c1b7d57ff1807"
3
}
Copied!
To use an ERC-20 token as a listing currency, the seller should add an erc20Address parameter to the call with the address of the smart contract of the ERC-20 token that is used for the listing.
The response is a transaction ID. The listing is now available in the marketplace and the seller should send the NFT asset being sold to the marketplace. The NFT can be sent using the following standard NFT transfer methods: ERC-721 and ERC-1155. The recipient is the NFT marketplace (i.e. the contractAddress in the call above).

Purchasing an NFT asset from a listing

Once the token is in the marketplace, it can be purchased from the NFT listing by any buyer with enough funds in their account. The buyer must enter the price of the listing + the marketplace fee.
The listing in the example is for 1 MATIC and the fee is 2.5%, so the buyer would have to spend 1.025 MATIC to buy the asset.
Use the following API call to purchase an NFT from a listing on the marketplace:
Request
Response
1
curl --location --request POST 'https://api-eu1.tatum.io/v3/blockchain/marketplace/listing/buy' \
2
--header 'Content-Type: application/json' \
3
--header 'x-api-key: YOUR_API_KEY' \
4
--data-raw '{
5
"contractAddress": "0x4153B909f55B0Ec43c11e980dF09b853477D9F79",
6
"listingId": "1200",
7
"amount": "0.002",
8
"chain": "MATIC",
9
"fromPrivateKey": "0xf09110a0aae3dddba3d722c6c629fb08082963d8ed38afaf25cfce084c22e3d2"
10
}'
Copied!
1
{
2
"txId": "0x18117c5e8fdef378c449c06c9306150067b499f04cb8ced8c0de6189d4246f8f"
3
}
Copied!
To use an ERC-20 token as a listing currency, the seller should add an erc20Address parameter to the call with the address of the smart contract of the ERC-20 token that is used for the listing.
The response is a transaction Id. In this operation, the NFT is transferred to the buyer, the amount is transferred to the seller, and the fee is transferred to the fee recipient of the marketplace.
You can take a look at an example transaction on the Mumbai Testnet. The buyer entered an even bigger amount to buy the NFT, so the rest was returned to him.
And that's it. For an ERC-20 listing, the only difference is that the buyer must approve the NFT marketplace to spend his ERC-20 tokens before the actual buy operation.
For ERC-1155 listings, the only difference is the number of tokens that are being listed.
Last modified 1mo ago