Skip to main content

contracts.marketplace

Interface for interacting with a marketplace contract

Marketplace Objects

class Marketplace(BaseContract[MarketplaceABI])

Create your own whitelabel marketplace that enables users to buy and sell any digital assets.

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}}")

get_listing

def get_listing(listing_id: int) -> Union[DirectListing, AuctionListing]

Get a listing from the marketplace by ID

Arguments:

  • listing_id: ID of the listing to get

Returns:

Listing object

get_active_listings

def get_active_listings() -> List[Union[DirectListing, AuctionListing]]

Get all the currently active listings from the marketplace.

listings = contract.get_active_listings()
price_of_first = listings[0].price

Returns:

List of listings

get_all_listings

def get_all_listings(
filter: MarketplaceFilter = None
) -> List[Union[DirectListing, AuctionListing]]

Get all the listings that have ever been made on this marketplace.

listings = contract.get_all_listings()
price_of_first = listings[0].price

Arguments:

  • filter: Filter to apply to the listings

Returns:

List of listings

get_total_count

def get_total_count() -> int

Get the total number of listings on this marketplace.

Returns:

Total number of listings

is_restricted_to_lister_role_only

def is_restricted_to_lister_role_only() -> bool

Check whether only wallets with the lister role can make listings.

Returns:

True if only lister wallets can make listings

get_bid_buffer_bps

def get_bid_buffer_bps() -> int

Get the bid buffer basis points for this marketplace.

Returns:

Bid buffer basis points

get_time_buffer_in_seconds

def get_time_buffer_in_seconds() -> int

Get the time buffer for this marketplace in seconds

Returns:

Time buffer in seconds

buyout_listing

def buyout_listing(listing_id: int,
quantity_desired: Optional[int] = None,
receiver: Optional[str] = None) -> TxReceipt

Buyout a listing by listing ID

listing_id = 0
quantity_desired = 1

contract.buyout_listing(listing_id, quantity_desired)

Arguments:

  • listing_id: ID of the listing to buyout
  • quantity_desired: Quantity to buyout
  • receiver: Address to send the asset to

Returns:

Transaction receipt of buyout

set_bid_buffer_bps

def set_bid_buffer_bps(buffer_bps: int) -> TxReceipt

Set the bid buffer basis points for this marketplace.

buffer_bps = 500
contract.set_bid_buffer_bps(buffer_bps)

Arguments:

  • buffer_bps: Bid buffer basis points

Returns:

Transaction receipt

set_time_buffer_in_seconds

def set_time_buffer_in_seconds(buffer_in_seconds: int) -> TxReceipt

Set the time buffer of the marketplace.

buffer_in_seconds = 60
contract.set_time_buffer_in_seconds(buffer_in_seconds)

Arguments:

  • buffer_in_seconds: Time buffer in seconds

Returns:

Transaction receipt

allow_listing_from_specific_asset_only

def allow_listing_from_specific_asset_only(contract_address: str) -> TxReceipt

Restrict marketplace so only specific asset can be listed.

Arguments:

  • contract_address: Address of the asset contract

allow_listing_from_any_asset

def allow_listing_from_any_asset() -> TxReceipt

Allow asset to be listed on the marketplace.

Returns:

Transaction receipt