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.
- Javascript
- React
- Python
- Go
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = new ThirdwebSDK("rinkeby");
const contract = sdk.getMarketplace("{{contract_address}}");
import { useMarketplace } from '@thirdweb-dev/react'
export default function Component() {
const marketplace = useMarketplace("<YOUR-CONTRACT-ADDRESS>")
// Now you can use the marketplace contract in the rest of the component
}
from thirdweb import ThirdwebSDK
from eth_account import Account
# You can customize this to a supported network or your own RPC URL
network = "mumbai"
# This will create a random account to use for signing transactions
signer = Account.create()
sdk = ThirdwebSDK(network, signer)
contract = sdk.get_marketplace("{{contract_address}}")
Go SDK support for initializing the SDK is coming soon.
Want this feature sooner? Let us know in Discord!
Creating Listings
There are two types of listings in marketplaces.
- 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.
- 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.
Using the SDK
Creating a new Direct Listing
- Javascript
- React
- Python
- Go
// 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);
React SDK support for direct is coming soon.
Want this feature sooner? Let us know in Discord!
Python SDK support for direct is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for direct is coming soon.
Want this feature sooner? Let us know in Discord!
Creating a new Auction Listing
- Javascript
- React
- Python
- Go
// 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);
React SDK support for auction is coming soon.
Want this feature sooner? Let us know in Discord!
Python SDK support for auction is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for auction is coming soon.
Want this feature sooner? Let us know in Discord!
Viewing Listings
All Listings
- Javascript
- React
- Python
- Go
const listings = await contract.getAllListings();
const priceOfFirstListing = listings[0].price;
React SDK support for getAllListings is coming soon.
Want this feature sooner? Let us know in Discord!
listings = contract.get_all_listings()
price_of_first = listings[0].price
Go SDK support for getAllListings is coming soon.
Want this feature sooner? Let us know in Discord!
Active Listings
This filters out listings that have finished, been cancelled, or have already been bought out.
- Javascript
- React
- Python
- Go
const listings = await contract.getActiveListings();
const priceOfFirstActiveListing = listings[0].price;
React SDK support for getActiveListings is coming soon.
Want this feature sooner? Let us know in Discord!
listings = contract.get_active_listings()
price_of_first = listings[0].price
Go SDK support for getActiveListings is coming soon.
Want this feature sooner? Let us know in Discord!
Buying an NFT from a Listing
- Javascript
- React
- Python
- Go
// 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);
React SDK support for buyoutListing is coming soon.
Want this feature sooner? Let us know in Discord!
listing_id = 0
quantity_desired = 1
contract.buyout_listing(listing_id, quantity_desired)
Go SDK support for buyoutListing is coming soon.
Want this feature sooner? Let us know in Discord!
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
- Javascript
- React
- Python
- Go
// the time buffer in seconds
const bufferInSeconds = 60;
await contract.setTimeBufferInSeconds(bufferInSeconds);
React SDK support for setTimeBufferInSeconds is coming soon.
Want this feature sooner? Let us know in Discord!
buffer_in_seconds = 60
contract.set_time_buffer_in_seconds(buffer_in_seconds)
Go SDK support for setTimeBufferInSeconds is coming soon.
Want this feature sooner? Let us know in Discord!
Set Bid Buffer
- Javascript
- React
- Python
- Go
// the bid buffer in basis points
const bufferBps = 500;
await contract.setBidBufferBps(bufferBps);
React SDK support for setBidBufferBps is coming soon.
Want this feature sooner? Let us know in Discord!
buffer_bps = 500
contract.set_bid_buffer_bps(buffer_bps)
Go SDK support for setBidBufferBps is coming soon.
Want this feature sooner? Let us know in Discord!