Complete your realtime crypto wallet by adding a visual display of a user’s NFT collection.
The user's full NFT collection, with artwork and details, displayed in the 'Collectibles' tab.
getWalletCollectibles
function to server.js
to fetch a user’s NFT collection using the Collectibles API.
entries
array within this response, providing information like contract addresses, token IDs, and chain data.
limit
and offset
query parameters.
For wallets with many NFTs, you can implement logic to fetch subsequent pages using the next_offset
value returned by the API to provide a complete view of the user’s collection..env
file:
getWalletCollectibles
function by adding OpenSea API integration to fetch images:
image_url
, opensea_url
, description
, and collection_name
fields, then filters to only return NFTs that have available images for display.
app.get('/')
route handler in server.js
to call this new function:
collectibles
array, now containing both blockchain data and image URLs, is passed to the wallet.ejs
template.
views/wallet.ejs
to render the fetched collectibles within the “Collectibles” tab.
We will use a grid layout to display NFT images with their collection names and token IDs.
In views/wallet.ejs
, find the section for the “Collectibles” tab (you can search for id="collectibles"
).
It currently contains a placeholder paragraph.
Replace that entire div
with the following EJS:
collectibles
array and displays each NFT with its enriched metadata.
Each collectible shows the image_url
from OpenSea, the collection_name
or fallback name, and a truncated token_id
for identification.
If an opensea_url
is available, the entire NFT card becomes a clickable link that opens the NFT’s OpenSea page in a new tab.
node server.js
and navigate to your wallet app in the browser.
When you click on the “Collectibles” tab, and if the wallet has NFTs, you should see the NFT collection displayed with rich visual metadata.