The Bazaar is a router for several smart contracts that allow users to list and trade NFTs.
This guide provides examples on how to interact with the Bazaar through your own custom interface. The guide includes detailed code examples with the use of wagmi and viem for ethereum interactions.
Prerequisites
Before proceeding, ensure your development environment is set up with the necessary libraries:
wagmi: A collection of React Hooks simplifying Ethereum blockchain interactions.
viem: A utility library for Ethereum address and transaction management.
Begin by adding the required libraries to your project. Execute the following commands in your terminal:
Using npm:
npminstallwagmiviem
Listing
There are many components required in order to set a sale price on an NFT with the Bazaar.
originContract // The token contract address
currencyAddress // Must be either the NULL address for ETH, or $RARE token address.
target // Specify an address that is allowed to purchase.
amount // The price of the NFT in currency units.
tokenId // The token number of the NFT to list.
splitRecipients // A list of addresses to each receive a portion of the sale price.
splitRatios // A list of ratios for each recipient to receive a portion of the sale price.
splitRecipients and splitRatios must be the same length and the ratios must add up to 100. for example:
To buy an NFT from the Bazaar, you need to call the buy function on the Bazaar contract. The NFT must have a sale price set and the buyer must have the required currency to purchase the NFT.
originContract // The token contract address
tokenId // The token number of the NFT to buy.
currencyAddress // Must be either the NULL address for ETH, or $RARE token address.
amount // The price of the NFT in currency units.
Like when setting the sale price, the amount should not include the 3% network fee. That will be added automatically by the contract when a sale is made.
The examples above are just a few of many functions available in the Bazaar contract. Largely the pattern is the same. You need to know the contract address, the function name, and the arguments required. Then you can use wagmi to call the function.
Look here for a full list of functions and their arguments.
Staking Rewards
The Bazaar contract natively handles staking rewards. When a sale of an NFT is made, the contract checks if there is an associated staking pool. And if so, 1% of the sale price is forwarded to the reward accumulator associated with that pool. Automatically. Nothing else is needed.
Tip: add reward accumulator to splits
To add larger reward amounts greater than 1% to the seller's pool, you can add the reward accumulator address to the splits argument. This will reward a portion of the sale price with the seller's pool.