I need help extracting CID values from NFT metadata on the Hedera network. When I mint NFTs, I store the CID as a uint8array, but when I query the blockchain data later, I get back something completely different.
The problem is that I can’t figure out how to convert the metadata back to the original CID format. I know the data is correct because when I check my NFT in wallet applications, all the images show up perfectly. The issue is just with processing the returned metadata on my end.
I’ve tried converting the metadata using different approaches like uint8array and other encoding methods, but nothing gives me the proper CID value. The returned data doesn’t seem to be in hex or binary format either.
Has anyone dealt with this before? I just want to get the original CID back so I can show the NFT images in my web application.
hm, have you tried converting it to base58? i had that issue too with ipfs, where the metadata was in a diff encoding. maybe using a base58 decoder will help you get the original cid back.
You’re likely dealing with encoding issues between different CID versions. When Hedera stores the metadata, it might be converting your CIDv1 to CIDv0 or vice versa. I ran into this exact problem last year with my marketplace project. The key is using the proper IPFS CID library to handle the conversion - something like js-cid or go-cid depending on your stack. Try parsing the returned bytes directly with the CID library instead of manual conversion. Also check if you’re storing the CID with the correct multibase encoding when minting. The wallet apps work because they handle these conversions automatically, but you need to implement the same logic in your application.
wait, are you sure you’re reading the metadata field correctly from hedera? i’m curious about which specific API endpoint you’re using to query the NFT data back. sometimes the issue isn’t with the CID conversion itself but how you’re extracting it from the token info response.
when you say you get “something completely different” - could you share what the raw data looks like? is it showing up as bytes, a string, or some other format? that might give us a clue about what’s happening during the storage/retrieval process.
also wondering - are you using the hedera sdk or making direct REST calls to the mirror node? i’ve noticed that different query methods sometimes return the metadata in slightly different formats, which could explain why your manual conversion attempts aren’t working but the wallets display everything fine.
if you could paste a sample of what you’re getting back vs what you expect, that would be super helpful for debugging this!