1

I try to use js-ipfs. First I import ipfs using CDN.

<script src="https://cdn.jsdelivr.net/npm/ipfs/dist/index.js"></script>

When I try ↓ this code, it worked well.

async function main (){
  const ipfs = await Ipfs.create()
  const cid = await ipfs.object.new({
    template: 'unixfs-dir'
  })
  window.alert(cid);
};
main();

However, When I try ↓ code, it doesn't work well.(reference: https://js.ipfs.io/)

async function main (){
  const ipfs = await Ipfs.create();
  const stream = ipfs.cat('QmPChd2hVbrJ6bfo3WBcTW4iZnpHm8TEzWkLHmLpXhF68A')
  let data = '';
  for await (const chunk of stream) {
    data += chunk.toString();
  };
  console.log(data);
};
main();

Please tell me what is the problem. I am stack in this point for 2 days.

MeRRy
  • 11
  • 1

0 Answers0