Home Blockchain Ens Content Hash第三方包
Post
Cancel

Blockchain Ens Content Hash第三方包

refer to:

https://github.com/ensdomains/content-hash

https://github.com/ensdomains/ensjs-v3/blob/main/packages/ensjs/src/utils/contentHash.ts

可以很方便的大家进行各种转换。

安装

npm install content-hash

使用

const contentHash = require('content-hash')

let string_from_ens_query = 'e30101701220fb542ce810ffbcfa68c8a64c7825a8408148822051ab959d448553d09c27df25'
let result = contentHash.decode(string_from_ens_query)
console.info("== result: ", result)

let string_from_ens_query_of_vitalik_eth = 'e30101701220d26f29c6d794c4957392c052bacd274b5d32790640c3ffec9fed0c32d8deccf9'

let v0_vitalik_eth = contentHash.decode(string_from_ens_query_of_vitalik_eth)
console.info("== vitalik.eth, result:", v0_vitalik_eth)
console.info("== vitalik.eth, CID v1:", contentHash.helpers.cidV0ToV1Base32(v0_vitalik_eth))

输出:

== result:  QmfFjVBz5wd66kyd89RWkJJiWEMq1Fde3XGN9MBfx47Btp
== vitalik.eth, result: QmcW6e33pgdHaQE4PLKLShEHeyWtzHthanjoyRhaRy9bdA
== vitalik.eth, CID v1: bafybeigsn4u4nv4uyskxhewakk5m2j2lluzhsbsayp76zh7nbqznrxwm7e

Demo 地址:

https://content-hash.surge.sh/

Content hash的来龙去脉:

This post is licensed under CC BY 4.0 by the author.