Marketplace
Learn how to interact with your Marketplace contract in the SDK.
Create a Marketplace Contract
- React
- Javascript
- Python
- Go
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",
});
Python SDK support for deployMarketplace is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for deployMarketplace is coming soon.
Want this feature sooner? Let us know in Discord!
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
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
}
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = new ThirdwebSDK("{{chainName}}");
const contract = sdk.getMarketplace("{{contract_address}}");
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/thirdweb"
)
privateKey = "..."
sdk, err := thirdweb.NewThirdwebSDK("mumbai", &thirdweb.SDKOptions{
PrivateKey: privateKey,
})
contract, err := sdk.GetMarketplace("{{contract_address}}")
Creating Listings
Creating a new Direct Listing
- React
- Javascript
- Python
- Go
// 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
Python SDK support for createListing is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for createListing is coming soon.
Want this feature sooner? Let us know in Discord!
Creating a new Auction Listing
- React
- Javascript
- 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 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
Python SDK support for createListing is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for createListing is coming soon.
Want this feature sooner? Let us know in Discord!
Viewing Listings
One Listing
- React
- Javascript
- Python
- Go
const { data: listing, isLoading, error } = useListing(<YourMarketplaceContractInstance>, <listingId>);
const listingId = 0;
const listing = await contract.getListing(listingId);
Python SDK support for getListing is coming soon.
Want this feature sooner? Let us know in Discord!
listingId := 0
listing, err := marketplace.GetListing(listingId)
All Listings
- React
- Javascript
- Python
- Go
const { data: listings, isLoading, error } = useListings(<YourMarketplaceContractInstance>, { start: 0, count: 100 });
const listings = await contract.getAllListings();
const priceOfFirstListing = listings[0].price;
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
- React
- Javascript
- Python
- Go
const { data: listings, isLoading, error } = useActiveListings(<YourMarketplaceContractInstance>, { seller: "0x...", tokenContract: "0x...", tokenId: 1, start: 0, count: 100 });
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()
// Price per token of the first listing
listings[0].BuyoutCurrencyValuePerToken.DisplayValue
Creating Offers / Bids
Direct Listings
Offers are made on direct listings.
- React
- Javascript
- Python
- Go
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
);
Python SDK support for makeOffer is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for makeOffer is coming soon.
Want this feature sooner? Let us know in Discord!
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
const Component = () => {
const {
mutate: makeBid,
isLoading,
error,
} = useMakeBid(">>YourMarketplaceContractInstance<<");
if (error) {
console.error("failed to make a bid", error);
}
return (
<button
disabled={isLoading}
onClick={() => makeBid({ listingId: 1, bid: 2 })}
>
Bid!
</button>
);
};
// 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);
Python SDK support for makeBid is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for makeBid is coming soon.
Want this feature sooner? Let us know in Discord!
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
// 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)
Go SDK support for buyoutListing is coming soon.
Want this feature sooner? Let us know in Discord!
Accept Offers (Direct Only)
Offers can only be accepted on direct listings.
- React
- Javascript
- Python
- Go
// 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);
Python SDK support for acceptOffer is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for acceptOffer is coming soon.
Want this feature sooner? Let us know in Discord!
Cancel a Listing
Direct Listing
- React
- Javascript
- Python
- Go
// 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);
Python SDK support for cancelListing is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for cancelListing is coming soon.
Want this feature sooner? Let us know in Discord!
Auction Listing
Auction listings cannot be canceled after a bid has been made.
- React
- Javascript
- Python
- Go
// 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);
Python SDK support for cancelListing is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for cancelListing is coming soon.
Want this feature sooner? Let us know in Discord!
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
// 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);
Python SDK support for closeListing is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for closeListing is coming soon.
Want this feature sooner? Let us know in Discord!
View Auction Bidding Info
Winning Bid
- React
- Javascript
- Python
- Go
const { data: winningBid, isLoading, error } = useWinningBid(<YourMarketplaceContractInstance>, <listingId>);
// 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));
Python SDK support for getWinningBid is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for getWinningBid is coming soon.
Want this feature sooner? Let us know in Discord!
Auction Winner
- React
- Javascript
- Python
- Go
// 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));
Python SDK support for getWinner is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for getWinner is coming soon.
Want this feature sooner? Let us know in Discord!
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
// 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)
Go SDK support for setTimeBufferInSeconds is coming soon.
Want this feature sooner? Let us know in Discord!
Set Bid Buffer
- React
- Javascript
- Python
- Go
// 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)
Go SDK support for setBidBufferBps is coming soon.
Want this feature sooner? Let us know in Discord!