Import
Usage
Make sure you have followed the Getting
Started guide
to get the collection address and chainId.
Examples
- Market Purchase
- Shop Purchase
Example of implementing a market purchase (secondary sales) using the
useBuyModal
hook:This example uses the
useLowestListing
hook from marketplace-sdk. If there is no lowestListing with the given parameters, it means there is no orderId available, and therefore the item cannot be bought.1
Setup handler component with marketplace config validation
First, create a main component that handles marketplace configuration loading and validation:
2
Create market purchase component
Next, create the actual market purchase component that uses properly validated data:
Parameters
The hook accepts an optionalcallbacks
object with the following properties:
Parameter | Type | Description |
---|---|---|
callbacks.onSuccess | ({ hash, orderId }: { hash?: Hash; orderId?: string }) => void | Optional callback function called when the purchase is successful |
callbacks.onError | (error: Error) => void | Optional callback function called when an error occurs during the purchase |
callbacks.successActionButtons | Array<{ label: string; action: () => void }> | Optional array of action buttons to show on success |
Return Type
The hook returns an object with the following methods:Methods
show
(args: BuyModalProps) => void
Opens the buy modal with the specified parameters. The BuyModalProps
can be either ShopBuyModalProps
or MarketplaceBuyModalProps
depending on the purchase type.
For market purchases (Secondary sales):
BuyModalBaseProps
:
close
() => void
Closes the buy modal.
Notes
TheuseBuyModal
hook provides a convenient way to manage the buy modal interface for collectible purchases. It handles:
- Opening and closing the modal
- Managing the purchase flow state
- Error handling and success callbacks
- Support for both primary and secondary sales