How can I call findProvs and findPeer from the client's browser?

Hello, I am building a project which visualizes the trajectory of DHT queries as you search for and locate provider records:

https://ipfs-globe.netlify.app/
GitHub - dwarkeshsp/ipfs-globe

Right now, I’m using one of IPFS’s delegate nodes to run findProvs and findPeer, the two IPFS functions I need for this project. This means the request is not originating from the client.

My question: Is there a way in which I can run findProvs and findPeer from the client’s computer via the browser, either by connecting to their daemon or by using the Brave integration, or something else?

1 Like

When I run:

const response = await fetch("http://127.0.0.1:5001/api/v0/version", {
  method: "POST",
  mode: "no-cors",
});
console.log(await response.text());

I get the error:

POST http://127.0.0.1:5001/api/v0/version 403 (Forbidden)

How do I get permission to access a user’s daemon through the HTTP API? BTW, I added mode: "no-cors" because before doing that, I was getting a cors error.

Thanks!

I still haven’t gotten a response on this yet. Does anyone know how I can get permission to access a user’s daemon through the HTTP API? Thanks a lot!

You can use the http client module - ipfs-http-client - npm - don’t forget to enable CORS headers in your daemon config.

Once you can connect successfully, see the DHT functions in the core-api docs for how to invoke findProvs and findPeer.

1 Like