Skip to main content

Marketplace

The Marketplace is a contract where you can buy and sell NFTs, such as to OpenSea or Rarible.

The Marketplace contract allows you to list your NFTs for direct listing or for auction. Other users can come and place offers/bids, or buy the NFTs for the amount that you specified in your listing. If you choose to, other users can also list their NFTs for sale on the marketplace too!

You could use the Marketplace contract to:

  • Sell your NFTs on your own marketplace
  • Create auctions where the highest bidder after a certain period of time wins the NFT
  • Create an open marketplace where any user can list NFTs for sale, like OpenSea.

Create a Marketplace Contract

Learn how to create any of thirdweb's pre-built contracts in the Deploying Contracts page.

Getting the contract in your application

To start using your Marketplace contract inside your application, you'll need to use it's contract address. You can get the contract address from the dashboard.

import { ThirdwebSDK } from "@thirdweb-dev/sdk";

const sdk = new ThirdwebSDK("rinkeby");
const contract = sdk.getMarketplace("{{contract_address}}");

Creating Listings

There are two types of listings in marketplaces.

  1. Direct Listings:
  • Sellers list their NFT for direct sale, with a price users can buy it for.
  • The NFT remains in your wallet, but you provide permission for the marketplace contract to move the NFT.
  • If a user pays the asking price, they will be transferred your NFT and the seller will receive the funds.
  • Users can make offers below the asking price, and the listing can have multiple offers at once, the seller can choose to accept an offer at any time.
  • Users can cancel their bids at any time.
  1. Auction Listings
  • Sellers list their NFT for auction, with a minimum asking price.
  • The NFT is transferred to escrow in the marketplace contract until the auction is cancelled or finished.
  • Other users can place bids until the auction is finished.
  • Users can only make a bid if it is higher than the current highest bid (or asking price if there are no bids). A bid cannot be cancelled, and the funds are held in escrow by the auction contract.
  • At the end of the auction, no more bids can be placed.
  • At the end of the auction, both the buyer and the seller call the closeAuction function. When the buyer calls it, they are transferred the funds from the highest bid, when the seller calls it, they are transferred the NFT.

Using the dashboard

Create a new listing by clicking the New Listing button in the dashboard.

Create A Listing via Marketplace Dashboard

Using the SDK

Creating a new Direct Listing

// Data of the listing you want to create
const listing = {
// address of the NFT contract the asset you want to list is on
assetContractAddress: "0x...",
// token ID of the asset you want to list
tokenId: "0",
// when should the listing open up for offers
startTimestamp: new Date(),
// how long the listing will be open for
listingDurationInSeconds: 86400,
// how many of the asset you want to list
quantity: 1,
// address of the currency contract that will be used to pay for the listing
currencyContractAddress: NATIVE_TOKEN_ADDRESS,
// how much the asset will be sold for
buyoutPricePerToken: "1.5",
}

const tx = await contract.direct.createListing(listing);
const receipt = tx.receipt; // the transaction receipt
const listingId = tx.id; // the id of the newly created listing

// And on the buyers side:
// Quantity of the asset you want to buy
const quantityDesired = 1;
await contract.direct.buyoutListing(listingId, quantityDesired);
View in Javascript SDK Documentation

Creating a new Auction Listing

// Data of the auction you want to create
const auction = {
// address of the contract the asset you want to list is on
assetContractAddress: "0x...",
// token ID of the asset you want to list
tokenId: "0",
// when should the listing open up for offers
startTimestamp: new Date(),
// how long the listing will be open for
listingDurationInSeconds: 86400,
// how many of the asset you want to list
quantity: 1,
// address of the currency contract that will be used to pay for the listing
currencyContractAddress: NATIVE_TOKEN_ADDRESS,
// how much people would have to bid to instantly buy the asset
buyoutPricePerToken: "10",
// the minimum bid that will be accepted for the token
reservePricePerToken: "1.5",
}

const tx = await contract.auction.createListing(auction);
const receipt = tx.receipt; // the transaction receipt
const listingId = tx.id; // the id of the newly created listing

// And on the buyers side:
// The price you are willing to bid for a single token of the listing
const pricePerToken = 2.6;
await contract.auction.makeBid(listingId, pricePerToken);
View in Javascript SDK Documentation

Viewing Listings

All Listings

const listings = await contract.getAllListings();
const priceOfFirstListing = listings[0].price;
View in Javascript SDK Documentation

Active Listings

This filters out listings that have finished, been cancelled, or have already been bought out.

const listings = await contract.getActiveListings();
const priceOfFirstActiveListing = listings[0].price;
View in Javascript SDK Documentation

Buying an NFT from a Listing

// The listing ID of the asset you want to buy
const listingId = 0;
// Quantity of the asset you want to buy
const quantityDesired = 1;

await contract.buyoutListing(listingId, quantityDesired);
View in Javascript SDK Documentation

Auction Bid Buffers

We made a few important considerations when it comes to auctions in our smart contract.

  • When someone makes a bid in an auction, the time until the auction is finished is extended by a set amount you can configure. This is to avoid users not bidding at the last possible second to win the auction.
  • The user must bid a certain percentage higher than the current highest bid. This is to avoid users bidding miniscule amounts above the previous bid.

Set Time Buffer

// the time buffer in seconds
const bufferInSeconds = 60;
await contract.setTimeBufferInSeconds(bufferInSeconds);
View in Javascript SDK Documentation

Set Bid Buffer

// the bid buffer in basis points
const bufferBps = 500;
await contract.setBidBufferBps(bufferBps);
View in Javascript SDK Documentation