I’m stuck trying to get NFT metadata from the Hedera chain. When we made the NFT, we changed the CID to unit8array. But now when I try to get the data back, it’s all messed up.
I can’t figure out how to retrieve the original CID value from the metadata. It’s odd because when I check the Hackpack wallet, I still see the NFT images, which means the data isn’t lost, it just isn’t formatted properly.
I’ve attempted to convert the input to different formats like [unit8array] and unit8array, but I keep getting some odd encoded value. The metadata output is neither in hex nor in binary format.
I really need to convert it back to a CID to display the NFT image on my website. Any suggestions on how to resolve this?
hey there Ben_Comics! sounds like you’re in a bit of a pickle with those NFT metadata. i’ve run into similar issues before and it can be super frustrating
have you tried using the IPFS gateway to retrieve the metadata? sometimes that can help bypass the encoding issues. Another thing to check - are you sure the CID you’re getting back is the full CID and not just a partial hash?
just brainstorming here, but what if you tried converting the unit8array back to a string first, then parsing that? might help get it into a more usable format.
also curious - what method are you using to query the metadata from hedera? there might be some SDK-specific quirks at play.
keep us posted on how it goes! nft stuff can be tricky but im sure youll figure it out
yo Ben, that sounds like a real headache! have u tried using a buffer to convert the uint8array back to a string? something like Buffer.from(uint8Array).toString(‘utf-8’) might do the trick. also, double-check ur metadata retrieval code - could be a sneaky bug in there messing things up. good luck man!
I’ve encountered similar issues when working with NFT metadata on Hedera. One approach that’s worked for me is using the @hashgraph/sdk library to properly decode the metadata. Specifically, the TokenNftInfo.getMetadata() method can help retrieve the original metadata in the correct format.
If that doesn’t work, you might need to implement a custom decoding function. Start by converting the uint8array to a buffer, then to a string, and finally parse it as JSON. Something like: