0

I got a site that fetchs data from ipfs network i am currently using it with axios.get("http://ipfs.io/ipfs...") and sometimes the blockchain is really slow, so i dont know is there another way to fetch fatest this data.

Maybe getting it directly with the ipfs protocol, how to do it using nodejs?

1 Answer 1

1

IPFS has nothing to do with a blockchain. It's a peer to peer file system. The host ipfs.io though is often overused so it can be slow.

I would try a different IPFS provider such as Cloudflare or infura.io (https://infura-ipfs.io/ipfs/). Be aware that they're often rate limited so better to probably role your own IPFS node.

If you want to connect to a different node via nodejs, then here's some code that might help:

import { create } from 'ipfs-http-client';
const fs = require('fs');

// and then call the below function
async function getIpfsFileAsArchive(ipfs, cid){
    for await (const buf of ipfs.get(cid, {archive: true, compress: true})) {
        const ipfs = await create({host: "replace with ipfs host ip address"});
        fs.createWriteStream(`./ipfs/${cid}.tar.gz`).write(buf);
    }
}
1
  • Awesome, thank you will use this to get it dono i think this is the right answer, thanks
    – JDLR
    Mar 4, 2022 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.