Let's say there is this ENS domain:
https://app.ens.domains/zh4ck.eth?tab=records
And it has it's content hash
ipns://k51qzi5uqu5dlodad1tur2ti64q55m1w8ipohvk0a52ebm4qlntay45hgdxqyb
But if I use any API to query the content hash for this ENS record, I get:
ipns://2D3KooWQepL1NNdw3RuvJp9f4cjUkkUZjwLHPn2HFWV6iTXVtKt
What is this second IPNS format? How can I convert this second format to the original one?
I tried Infura and Cloudflare API.
var ethers = require('ethers')
const provider =new ethers.InfuraProvider( "homestead" , ‘MY_API’ )
const resolver = await provider.getResolver('zh4ck.eth')
await resolver.getContentHash()
'ipns://2D3KooWQepL1NNdw3RuvJp9f4cjUkkUZjwLHPn2HFWV6iTXVtKt'
thank you
The first hash is in the older format that only encodes the content hash, while the second one is in the new format because it looks like a Base32 encoded CID (Content Identifier), used later, by IPFS, to identify a file.
Earlier versions of IPFS used a different hash function, and later versions upgraded to using CID which also includes versioning and codec information, more future-proof to support different types of content.
To convert between these formats, decode the Base32 CID to get the original hash.
Example using the
cids
library in js: