multiformats / js-cid

CID implementation in JavaScript
MIT License
97 stars 39 forks source link

how to convert from hex to cid. #142

Closed novaknole closed 3 years ago

novaknole commented 3 years ago

Let’s say I get the cid when I push a file to ipfs. now, I need to store it in solidity’s bytes variable. because it’s a bytes variable, i can’t directly send cid as it will fail. So I transform the cid into hex depending on which base the cid uses. The hex goes to solidity.

After some time, solidity throws the event which I catch in my another client(javascript). Now I need to somehow get the CiD again from this hex. How do I do this ? The tricky part is that I don’t know if while getting the hex, which base was used which means I could have gotten the hex of cid v0 or v1.

What would be the right way ? Definatelly, I need to know which base was used so that I can decode from hex to cid again.

lidel commented 3 years ago

I replied in https://discuss.ipfs.io/t/how-to-convert-from-hex-to-cid/10708/12?u=lidel :-)

I'm closing this one: we use github only for bug reports and feature requests. In the future, please keep questions like this to https://discuss.ipfs.io