Marketplace
Learn how to interact with your Marketplace contract in the SDK.
Create a Marketplace Contract
- React
- Javascript
- Python
- Go
- Unity
const sdk = useSDK();
const contractAddress = await sdk.deployer.deployMarketplace({
name: "My Marketplace",
primary_sale_recipient: "your-address",
});
const contractAddress = await sdk.deployer.deployMarketplace({
name: "My Marketplace",
primary_sale_recipient: "your-address",
});
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
await sdk
.deployer
.DeployMarketplace(new MarketplaceContractDeployMetadata()
{ name = "My Collection" });
Getting the contract in your application
To start using your Marketplace contract inside your application, you'll need to use its contract address. You can get the contract address from the dashboard.
- React
- Javascript
- Python
- Go
- Unity
This feature is missing a code snippet or might not be supported yet.
Check the React SDK Reference for more information.
Reach out on Discord for further assistance!
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = new ThirdwebSDK("{{chainName}}");
const contract = await sdk.getContract("{{contract_address}}", "marketplace");
from thirdweb import ThirdwebSDK
# You can customize this to a supported network or your own RPC URL
network = "mumbai"
# Now we can create a new instance of the SDK
sdk = ThirdwebSDK(network)
# If you want to send transactions, you can instantiate the SDK with a private key instead:
# sdk = ThirdwebSDK.from_private_key(PRIVATE_KEY, network)
contract = sdk.get_marketplace("{{contract_address}}")
import (
"github.com/thirdweb-dev/go-sdk/v2/thirdweb"
)
privateKey = "..."
sdk, err := thirdweb.NewThirdwebSDK("mumbai", &thirdweb.SDKOptions{
PrivateKey: privateKey,
})
contract, err := sdk.GetMarketplace("{{contract_address}}")
Marketplace contract = sdk.GetContract("{{contract_address}}").marketplace;
Creating Listings
Creating a new Direct Listing
- React
- Javascript
- Python
- Go
- Unity
// Data of the listing you want to create
const listing = {
// 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 the asset will be sold for
buyoutPricePerToken: "1.5",
}
const tx = await contract.direct.createListing(listing);
const receipt = tx.receipt; // the transaction receipt
const id = tx.id; // the id of the newly created listing
// Data of the listing you want to create
const listing = {
// 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 the asset will be sold for
buyoutPricePerToken: "1.5",
}
const tx = await contract.direct.createListing(listing);
const receipt = tx.receipt; // the transaction receipt
const id = tx.id; // the id of the newly created listing
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
await contract
.direct
.CreateListing(new NewDirectListing()
{
assetContractAddress = "0x...",
buyoutPricePerToken = "1",
currencyContractAddress = "0x...",
listingDurationInSeconds = 3600,
quantity = 1,
reservePricePerToken = "0",
startTimestamp = 0,
tokenId = "1",
type = "direct"
});
Creating a new Auction Listing
- React
- Javascript
- Python
- Go
- Unity
// 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 id = tx.id; // the id of the newly created 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 id = tx.id; // the id of the newly created listing
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
await contract
.direct
.CreateListing(new NewDirectListing()
{
assetContractAddress = "0x...",
buyoutPricePerToken = "1",
currencyContractAddress = "0x...",
listingDurationInSeconds = 3600,
quantity = 1,
reservePricePerToken = "0",
startTimestamp = 0,
tokenId = "1",
type = "auction"
});
Viewing Listings
One Listing
- React
- Javascript
- Python
- Go
- Unity
const listingId = 0;
const listing = await contract.getListing(listingId);
const listingId = 0;
const listing = await contract.getListing(listingId);
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
listingId := 0
listing, err := marketplace.GetListing(context.Background(), listingId)
var listingId = "0";
var listing = await contract.GetListing(listingId);
All Listings
- React
- Javascript
- Python
- Go
- Unity
const listings = await contract.getAllListings();
const priceOfFirstListing = listings[0].price;
const listings = await contract.getAllListings();
const priceOfFirstListing = listings[0].price;
listings = contract.get_all_listings()
price_of_first = listings[0].price
listings, err := marketplace.GetAllListings(context.Background(), nil)
// Price per token of the first listing
listings[0].BuyoutCurrencyValuePerToken.DisplayValue
var listings = await contract.GetAllListings();
Active Listings
- React
- Javascript
- Python
- Go
- Unity
const listings = await contract.getActiveListings();
const priceOfFirstActiveListing = listings[0].price;
const listings = await contract.getActiveListings();
const priceOfFirstActiveListing = listings[0].price;
listings = contract.get_active_listings()
price_of_first = listings[0].price
listings, err := marketplace.GetActiveListings(context.Background(), nil)
// Price per token of the first listing
listings[0].BuyoutCurrencyValuePerToken.DisplayValue
var listings = await contract.GetActiveListings();
Creating Offers / Bids
Direct Listings
Offers are made on direct listings.
- React
- Javascript
- Python
- Go
- Unity
const sdk = useSDK();
import { ChainId, NATIVE_TOKENS } from "@thirdweb-dev/sdk";
// The listing ID of the asset you want to offer on
const listingId = 0;
// The price you are willing to offer per token
const pricePerToken = 1;
// The quantity of tokens you want to receive for this offer
const quantity = 1;
// The address of the currency you are making the offer in (must be ERC-20)
const currencyContractAddress = NATIVE_TOKENS[ChainId.Rinkeby].wrapped.address
await contract.direct.makeOffer(
listingId,
quantity,
currencyContractAddress,
pricePerToken
);
import { ChainId, NATIVE_TOKENS } from "@thirdweb-dev/sdk";
// The listing ID of the asset you want to offer on
const listingId = 0;
// The price you are willing to offer per token
const pricePerToken = 1;
// The quantity of tokens you want to receive for this offer
const quantity = 1;
// The address of the currency you are making the offer in (must be ERC-20)
const currencyContractAddress = NATIVE_TOKENS[ChainId.Rinkeby].wrapped.address
await contract.direct.makeOffer(
listingId,
quantity,
currencyContractAddress,
pricePerToken
);
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
string listingId = "0";
string price = "0.1";
int quantity = 1;
await contract.MakeOffer(listingId, price, quantity);
Auction Listings
Bids are made on auction listings.
- Once a bid is made, it cannot be withdrawn.
- Bids must be higher than either the reserve price, OR if there is an existing bid, it must be higher than the current bid by a certain percentage - (see Auction Bid Buffers).
- The previous highest bid is refunded automatically when a higher bid is made.
- React
- Javascript
- Python
- Go
- Unity
// The listing ID of the asset you want to bid on
const listingId = 0;
// The price you are willing to bid for a single token of the listing
const pricePerToken = 1;
await contract.auction.makeBid(listingId, pricePerToken);
// The listing ID of the asset you want to bid on
const listingId = 0;
// The price you are willing to bid for a single token of the listing
const pricePerToken = 1;
await contract.auction.makeBid(listingId, pricePerToken);
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
string listingId = "0";
string price = "0.1";
int quantity = 1;
await contract.MakeOffer(listingId, price, quantity);
Buying an NFT from a Listing
Buying a listing is the same for both direct listings and auction listings.
When a buyout
is made, the NFT is transferred to the buyer, and the seller receives the funds immediately.
- React
- Javascript
- Python
- Go
- Unity
// 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);
// 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);
listing_id = 0
quantity_desired = 1
contract.buyout_listing(listing_id, quantity_desired)
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
// The listing ID of the asset you want to buy
var listingId = "0";
// Quantity of the asset you want to buy
var quantityDesired = 1;
await contract.BuyoutListing(listingId, quantityDesired);
Accept Offers (Direct Only)
Offers can only be accepted on direct listings.
- React
- Javascript
- Python
- Go
- Unity
// The listing ID of the asset you want to bid on
const listingId = 0;
// The price you are willing to bid for a single token of the listing
const offeror = "0x...";
await contract.direct.acceptOffer(listingId, offeror);
// The listing ID of the asset you want to bid on
const listingId = 0;
// The price you are willing to bid for a single token of the listing
const offeror = "0x...";
await contract.direct.acceptOffer(listingId, offeror);
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!
Cancel a Listing
Direct Listing
- React
- Javascript
- Python
- Go
- Unity
// The listing ID of the direct listing you want to cancel
const listingId = "0";
await contract.direct.cancelListing(listingId);
// The listing ID of the direct listing you want to cancel
const listingId = "0";
await contract.direct.cancelListing(listingId);
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
string listingId = "0";
await contract.direct.CancelListing(listingId);
Auction Listing
Auction listings cannot be canceled after a bid has been made.
- React
- Javascript
- Python
- Go
- Unity
// The listing ID of the auction listing you want to cancel
const listingId = "0";
await contract.auction.cancelListing(listingId);
// The listing ID of the auction listing you want to cancel
const listingId = "0";
await contract.auction.cancelListing(listingId);
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
string listingId = "0";
await contract.auction.CancelListing(listingId);
Close a Listing (Auction Only)
When an auction is finished, the closeAuction
needs to be called for both the buyer and the seller.
The closeAuction
function takes in a closeFor
parameter.
When the
closeFor
value is the address of the buyer, they are transferred the funds from the highest bid.When the
closeFor
value is the address of the seller, the NFT is transferred to them.
- React
- Javascript
- Python
- Go
- Unity
// The listing ID of the auction listing you want to close
const listingId = "0";
await contract.auction.closeListing(listingId);
// The listing ID of the auction listing you want to close
const listingId = "0";
await contract.auction.closeListing(listingId);
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
string listingId = "0";
await contract.auction.ExecuteSale(listingId);
View Auction Bidding Info
Winning Bid
- React
- Javascript
- Python
- Go
- Unity
// The listing ID of the auction that closed
const listingId = 0;
contract.auction.
.getWinningBid(listingId)
.then((offer) => console.log(offer))
.catch((err) => console.error(err));
// The listing ID of the auction that closed
const listingId = 0;
contract.auction.
.getWinningBid(listingId)
.then((offer) => console.log(offer))
.catch((err) => console.error(err));
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
string listingId = "0";
await contract.auction.GetWinningBid(listingId);
Auction Winner
- React
- Javascript
- Python
- Go
- Unity
// The listing ID of the auction that closed
const listingId = 0;
contract.auction.
.getWinner(listingId)
.then((auctionWinner) => console.log(auctionWinner))
.catch((err) => console.error(err));
// The listing ID of the auction that closed
const listingId = 0;
contract.auction.
.getWinner(listingId)
.then((auctionWinner) => console.log(auctionWinner))
.catch((err) => console.error(err));
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
string listingId = "0";
await contract.auction.GetWinner(listingId);
Auction Bid Buffers
We made a few important considerations for 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 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 to prevent users from bidding minuscule amounts above the previous bid.
Set Time Buffer
- React
- Javascript
- Python
- Go
- Unity
// the time buffer in seconds
const bufferInSeconds = 60;
await contract.setTimeBufferInSeconds(bufferInSeconds);
// the time buffer in seconds
const bufferInSeconds = 60;
await contract.setTimeBufferInSeconds(bufferInSeconds);
buffer_in_seconds = 60
contract.set_time_buffer_in_seconds(buffer_in_seconds)
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!
Set Bid Buffer
- React
- Javascript
- Python
- Go
- Unity
// the bid buffer in basis points
const bufferBps = 5_00; // 5%
await contract.setBidBufferBps(bufferBps);
// the bid buffer in basis points
const bufferBps = 5_00; // 5%
await contract.setBidBufferBps(bufferBps);
buffer_bps = 500
contract.set_bid_buffer_bps(buffer_bps)
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!