I’m working with NFTs on the Hedera network and having trouble extracting the original CID from the metadata.
When I created the NFT, I stored the CID in uint8array format. However, when I retrieve the NFT data from the mirror node API, the metadata comes back in a format that I can’t decode properly.
The NFT images display correctly in HashPack wallet, so I know the metadata is intact. But when I try to process it programmatically, I get encoded values that don’t match the original CID format.
I’ve attempted converting the metadata using different approaches like uint8array parsing, but the output doesn’t appear to be standard hex or binary encoding.
What’s the correct way to decode Hedera NFT metadata back to the original CID format so I can show the images in my web application?
Interesting issue! What’s your setup - hitting the mirror node directly or using a wrapper?
I’ve been messing with Hedera NFTs too and the metadata structure varies a lot based on how it was minted. When you stored it as uint8array during creation, did you use any metadata standard like the typical NFT JSON schema?
Also - what do those encoded values look like when you get them back? Long hex strings or garbled text? That’d help figure out what encoding we’re dealing with.
Hashpack displaying them correctly is a good sign though! Probably just missing one decode step. Have you checked the raw response in your browser’s network tab when you hit the mirror node? Sometimes seeing the exact structure helps figure out what decoding you need.
The mirror node gives you metadata as base64-encoded bytes, but here’s what trips people up. After you decode the base64, you’ve got to parse the JSON - Hedera stuffs metadata into JSON with the CID usually sitting in an “image” or “url” field. I hit this same wall last month. Was trying to decode straight to the CID when I should’ve parsed the JSON first. Run JSON.parse() after your base64 decode, then grab the image field. You’ll find your IPFS CID formatted as “ipfs://[your-cid-here]”. Strip off that ipfs:// prefix and you’re good to go with whatever IPFS gateway you prefer.
your metadata’s probably base64 encoded from the mirror node. use atob() or Buffer.from(metadata, ‘base64’) to decode it, then convert to string. fixed the same issue on my NFT project.