This guide will walk you through the process of listing NFT(s) using the Rarible SDK.
Prerequisite
Follow our Getting started guide to install needed libraries and instantiate SDK.
Listing an NFT
To list an NFT, follow these steps:
- Connect Wallet: Ensure the user's wallet is connected. This can be done using wallet connect protocols.
- Create an NFT Item: Before listing, you need to have an NFT item. If you don't have one, you can create it using the Rarible SDK's minting function.
- List the NFT: Use the sell function from the SDK to list your NFT. Here's an example:
const orderId = await sdk.sell({
itemId: "ETHEREUM:YOUR_NFT_CONTRACT_ADDRESS:TOKEN_ID",
amount: 1, // amount of NFTs to sell
price: "0.1",
currency: toCurrencyId("ETHEREUM:0x0000000000000000000000000000000000000000"), //check toCurrencyId jsdoc for more examples
});
console.log(`Successfully listed. Order ID: ${orderId}`);
*Replace YOUR_NFT_CONTRACT_ADDRESS and TOKEN_ID with your NFT's contract address and token ID.
- Confirm Transaction: The user will need to confirm the transaction in their wallet and sign order message.
- Check Listing: Once the transaction is confirmed and order message is signed, the NFT will be listed on Rarible
Clarification
Often when listing an item for sale, you need to list it in the native currency of the blockchain. You can see a list of supported currencies on Rarible here. However, you are not limited in your choice of currencies when listing an item for sale and can use any ERC-20 token.
Conclusion
Listing NFTs using the Rarible SDK is a straightforward process. By following the steps outlined in this guide, developers can easily integrate NFT listing functionality into their applications. Remember to handle user authentication and wallet connections securely, and always test your implementation thoroughly.