Js-IPFS Error: cid.toBaseEncodedString() is not a function

234 Views Asked by At

I'm currently working on the backend of a website that would work similar to YouTube but only use IPFS for storage, meaning if you want to "upload" videos to the site it would already have to be on the IPFS network. The actual function is more of an Index than anything else but it was something that I wanted to tackle.

The section I'm working on is intended to verify the integrity of the CID hashes by making sure that there are still providers on the network for that specific content. If there aren't any then the CID and any information associated will get removed from my database but I'm currently getting an issue when trying using the ipfs.dhs.findProvs function.

Here is part of my code:

const ipfs = await IPFS.create({
  libp2p: { config: { dht: { enabled: true } } },
});
for (var i of integrityData) {
  let cid = new CID(i.CID);
  console.log(cid);
  let providers = ipfs.dht.findProvs(cid, { numProviders: 2 });
  for await (const provider of providers) {
    console.log(provider);
  }
}

Error Log:

C:\Users\...\node_modules\libp2p-kad-dht\src\providers.js:202
      this._log('getProviders %s', cid.toBaseEncodedString())
                                       ^

TypeError: cid.toBaseEncodedString is not a function

To further explain my code, the for loops is iterating the JSON content received the Database after querying for all the CIDs in it. i.CID does return the correct CID as a string which I then create a CID object from and pass to the function here ipfs.dht.findProvs(cid, { numProviders: 2 });. The nested for loop is there to iterate through the object that is received but I haven't made it to that stage as I keep getting the same error.

0

There are 0 best solutions below