Leverage the CollectModal to add minting and sweeping to your app with ReservoirKit.
The CollectModal was deprecated in v1.24Please use the MintModal and SweepModal if using v.1.24 or higher.
CollectModal provides a simple method to mint or sweep the collection based on its current state.
Prerequisites ⚙️
Install and configure ReservoirKit.
CollectModal Setup
ReservoirKit provides a simple to configure modal for adding both minting and sweeping to your react app. Below is an example of a simple CollectModal setup.
import { CollectModal } from '@reservoir0x/reservoir-kit-ui'
<CollectModal
trigger={
<button>
Collect
</button>
}
collectionId="0xf5de760f2e916647fd766b4ad9e85ff943ce3a2b"
mode="preferMint"
onCollectComplete={(data) => {
console.log('Collect Complete', data)
}}
onCollectError={(error, data) => {
console.log('Collect Error', error, data)
}}
onClose={(data, currentStep) => {
console.log('CollectModal Closed')
}}
/>Let's dive into the parameters:
Prop | Description | Required |
|---|---|---|
trigger | A react node that will be presented to the user, usually a button or something clickable. | Y |
collectionId | The collection id of the collection you wish to mint/sweep. Can be undefined until the data is ready. | Y |
onConnectWallet | A function that beings the connect wallet flow. Use this to prompt your connect modal and continue the ux of connecting the user's wallet. | Y |
tokenId | The token id of the token you wish to mint/sweep. Can be undefined until the data is ready.
| N |
mode | There are three possible modes for the CollectModal:
The default behavior is | N |
openState | This is a state tuple from react's useState, you can use this to programmatically open or close the modal. The modal will use this state when determining if the modal is open or closed. | N |
copyOverrides | An object containing copy overrides for titles and ctas contained in the modal. Refer to the | N |
feesOnTopBps | Used to conditionally apply a referral fee on top of an order when purchasing. The parameter is an array of strings with the referrer and the fee separated by a colon: | N |
feesOnTopUsd | Used to conditionally apply a referral fee on top of an order when purchasing. The parameter is an array of strings with the referrer and the fee separated by a colon: | N |
normalizeRoyalties | Use this to ensure that royalties are added to the order. If royalties are missing from the order then the correct royalties are added on top. If unspecified then the global setting will be used if provided. | N |
chainId | The chain id to force the modal to render, ensure that this is a chain that is configured in the ReservoirKit provider. If not specified then the active chain configured in the ReservoirKitProvider will be used. | N |
walletClient | A valid WalletClient from viem or a ReservoirWallet generated from an adapter. Learn more about adapters | N |
usePermit | Use permit to avoid approvals, enable this if you want to support gasless meta transactions. Ensure that you're using gelato via the adapter and you have usdc as the only paymentToken or you may run into issues. | N |
defaultQuantity | The default quantity to open the modal with, if the quantity available is higher than the default then the maximum is prefilled | N |
onCollectComplete | Triggered when the mint/sweep was completed successfully, returns some useful data about the transaction. | N |
onCollectError | Triggered when the mint resulted in an error, returns the error and the mint data. | N |
onClose | Triggered when the modal was closed. Returns some useful data about the mint as well as and the current step. | N |
Custom CollectModal
The CollectModal also comes with a custom renderer which can be used to just get the data layer that the CollectModal uses internally to handle the underlying business logic. With the renderer you can rebuild the UI completely to your liking. Below is an example of how it works in practice.
import { CollectModal, CollectStep } from '@reservoir0x/reservoir-kit-ui'
<CollectModal.Custom
open={open}
collectionId={collectionId}>
{({
contentMode,
collection,
token,
loading,
address,
selectedTokens,
setSelectedTokens,
itemAmount,
setItemAmount,
maxItemAmount,
setMaxItemAmount,
paymentCurrency,
setPaymentCurrency,
chainCurrency,
paymentTokens,
total,
totalIncludingFees,
feeOnTop,
feeUsd,
usdPrice,
usdPriceRaw,
isConnected,
currentChain,
mintPrice,
orders,
balance,
contract,
hasEnoughCurrency,
addFundsLink,
blockExplorerBaseUrl,
transactionError,
stepData,
setStepData,
collectStep,
setCollectStep,
collectTokens,
}) => {
{ Your Custom React Elements }
})}
</CollectModal.Custom>The custom CollectModal takes a few parameters like before with one additional one being the open parameter. This is because there is no trigger, you have control over what sort of modal you want this to eventually live in and how to trigger that modal. You'll have the ability to add a custom button with a custom handler, etc. The custom CollectModal then passes some key data into the children which we parse above and use in our custom UI. It's also important to note the CollectStep here which is used to manage the internal state of the CollectModal's logic. You can decide to use all or some of the data passed into your custom implementation.