How recreate a hash digest of a multihash in IPFS

前端 未结 3 932
猫巷女王i
猫巷女王i 2021-01-12 20:24

Assuming I\'m adding data to IPFS like this:

$ echo Hello World | ipfs add

This will give me QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJ

3条回答
  •  佛祖请我去吃肉
    2021-01-12 20:47

    I'm not sure what that encoding is but you can unmarshal the dag data field like this in js-ipfs:

    const IPFS = require('ipfs')
    const Unixfs = require('ipfs-unixfs')
    
    const ipfs = new IPFS
    
    ipfs.dag.get('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u', (err, d) => {
      console.log(Unixfs.unmarshal(d.value.data).data.toString()))
      // prints Hello World
    })

提交回复
热议问题