Tatum
Search…
How to create a peer-to-peer NFT auction
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. Users can create fixed-price listings for their NFTs or put them up for auction and sell them to the highest bidder.
Creating NFTs has always been super simple with Tatum. However, peer-to-peer NFT auctions can take a bit of work to implement properly. So we've created out-of-the-box NFT auction functionality that can be deployed in just a few minutes.
When an 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.
Check out our tutorial video and read through all the steps and API calls below.
Auction.postman_collection.json
30KB
Binary
Auction Postman collection
With this type of marketplace, your users can create auctions 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.

Create an auction house

The first step is to create your own auction house smart contract. This is a one-time operation, and the auction house you deploy will be used for every listing in your application. In this example, we'll deploy our auction house on the Polygon network.
Request
Response
1
curl --location --request POST 'https://api-eu1.tatum.io/v3/blockchain/marketplace/auction' \
2
--header 'Content-Type: application/json' \
3
--header 'x-api-key: YOUR_API_KEY' \
4
--data-raw '{
5
"feeRecipient": "0x8cb76aEd9C5e336ef961265c6079C14e9cD3D2eA",
6
"auctionFee": 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 "auctionFee" 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 at your auction.
The address "feeRecipient" field is where the fees will be sent, i.e. your address as the auction house owner.
The response is a transaction ID from which we can obtain the contract address.

Create an auction

Once the auction house contract is ready, you can enable auctions for your users. The NFT asset must be present at the address of the seller before they create an NFT auction. The seller must approve the spending of the NFT asset to the auction house contract.
Request
Response
1
curl --location --request POST 'https://api-eu1.tatum.io/v3/blockchain/auction/approve' \
2
--header 'Content-Type: application/json' \
3
--header 'x-api-key: YOUR_API_KEY' \
4
--data-raw '{
5
"spender": "0xb36abab0c1365335dd762815aaae40dd1b990f99",
6
"contractAddress": "0x6d8eae641416b8b79e0fb3a92b17448cfff02b11",
7
"tokenId": "124",
8
"isErc721": true,
9
"chain": "MATIC",
10
"fromPrivateKey": "0x37b091fc4ce46a56da643f021254612551dbe0944679a6e09cb5724d3085c9ab"
11
}'
Copied!
1
{
2
"txId": "0x53e19422eec0a0bb20b3c2f43c30b8c30745e8e0265fea0359b56c72a0293f9a"
3
}
Copied!
The seller can choose 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 auction must have a unique id. This ID identifies the auction and is used for performing other operations.
The following API call will create a time-based NFT auction on your marketplace. You need to define the latest block in which the auction will accept bids.
Request
Response
1
curl --location --request POST 'https://api-eu1.tatum.io/v3/blockchain/auction/sell' \
2
--header 'Content-Type: application/json' \
3
--header 'x-api-key: YOUR_API_KEY' \
4
--data-raw '{
5
"contractAddress": "0xb36abab0c1365335dd762815aaae40dd1b990f99",
6
"nftAddress": "0x6d8eae641416b8b79e0fb3a92b17448cfff02b11",
7
"tokenId": "124",
8
"id": "1",
9
"isErc721": true,
10
"endedAt": 18302000,
11
"seller": "0x80D8BAc9a6901698b3749Fe336bBd1385C1f98f2",
12
"chain": "MATIC",
13
"fromPrivateKey": "0x37b091fc4ce46a56da643f021254612551dbe0944679a6e09cb5724d3085c9ab"
14
}'
Copied!
1
{
2
"txId": "0xa40b252649e8e6419592d4c9f6639577f556f4f9d6a744982a30fd2f383b3e42"
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 auction house and available for bids.

Bidding for the auction

Once the token is in the auction, anyone can bid. Only bids higher than the highest current bid are accepted. The previous bid is returned to the bidder. The buyer must enter the price of the asset + 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 bid for the NFT.
Request
Response
1
curl --location --request POST 'https://api-eu1.tatum.io/v3/blockchain/auction/bid' \
2
--header 'Content-Type: application/json' \
3
--header 'x-api-key: YOUR_API_KEY' \
4
--data-raw '{
5
"contractAddress": "0xb36abab0c1365335dd762815aaae40dd1b990f99",
6
"id": "1",
7
"bidValue": "0.002",
8
"chain": "MATIC",
9
"fromPrivateKey": "0xf09110a0aae3dddba3d722c6c629fb08082963d8ed38afaf25cfce084c22e3d2"
10
}'
Copied!
1
{
2
"txId": "0x99c563e81353bc2f24646b784687892398a0b0b2261c9870be3aee46552a063c"
3
}
Copied!
The response is a transaction ID. In this operation, the bidder sends his bid to the auction house contract.

Settlement of the auction

Once the auction ends and can't accept more bids, anyone can settle the auction. Settlement can't be done on the live auction. 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.
Use the following API call to settle for the NFT.
Request
Response
1
curl --location --request POST 'https://api-eu1.tatum.io/v3/blockchain/auction/settle' \
2
--header 'Content-Type: application/json' \
3
--header 'x-api-key: YOUR_API_KEY' \
4
--data-raw '{
5
"contractAddress": "0xb36abab0c1365335dd762815aaae40dd1b990f99",
6
"id": "1",
7
"chain": "MATIC",
8
"fromPrivateKey": "0xf09110a0aae3dddba3d722c6c629fb08082963d8ed38afaf25cfce084c22e3d2"
9
}'
Copied!
1
{
2
"txId": "0x9a5aa635b2e55e39dac7007603969776ced92ce1f209f57b7888b7642a56dc6d"
3
}
Copied!
The response is a transaction ID.
You can take a look at an example transaction on the Mumbai Testnet.
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