A way to represent anything unique as an Ethereum-based asset.
NFTs are giving more power to content creators than ever before.
Powered by smart contracts on the Ethereum blockchain.
OpenSea is the world's first and largest NFT marketplace. It can be used to discover, collect, and sell extraordinary NFTs.
In this article, I will show how I fetch all my collections using OpenSea's API and then display them on my website.
Prerequisite
For us to be able to use OpenSea's API, we need to request an OpenSea API key here
Create a reusable options object for each API call
This will contain the API key provided by OpenSea
.js
12345678const options ={method:'GET',headers:{Accept:'application/json',// Do not expose your API key in the browser'X-API-KEY': process.env.OPENSEA_API,},};
To avoid exposing your API key, refer to this blog.
(OPTIONAL) Create a variable for the wallet's address
This is the address of our wallet. We can use this address to fetch our collections and assets.
It will depend on the frontend framework of choice. Here is how I did it using NextJs.
NOTE: The overall API requests might be slow when fetched from the browser, make sure to have an appropriate content loader in place. Caching the response might help as well.
Demo
What's next?
Add functionalities for visitors to make offers and buy my NFT collection.