18

I have javascript app (ReactJs) which will run as an android hybrid app on mobile devices. I do not want to run full IPFS node on a mobile device, because it will consume a lot of its memory and energy. How can I connect my app to IPFS then?

I saw https://github.com/ipfs/js-ipfs-api#importing-the-module-and-usage, but it does not look usable for a mobile device again as it runs as a separated service.

Probably I have to connect to some IPFS node at the internet through IPFS API (https://ipfs.io/docs/api/), however is there a way to discover running nodes on the runtime and also to choose the fastest/closest one?

user3024710
  • 515
  • 1
  • 6
  • 15

2 Answers2

7

You have a couple of options here:

  • You can host an IPFS node in some cloud and have all your mobile devices connect to it
  • Run a js-ipfs node instance when you need it and garbage collect it afterward.

Are you developing a PWA? js-ipfs works well on Chrome in Android phones, check https://github.com/ipfs/js-ipfs/tree/master/examples to learn how to get started.

David Dias
  • 1,792
  • 3
  • 16
  • 28
5

My experience, at least so far, is that there aren't really any good wrappers for IPFS, in any language. At least, not yet. But that's okay, because it's really simple to use. Just remember that it returns hashes in the headers when you add a file, not in the response body like you might expect. That really screwed me up. Other than that, there's nothing to it.

As far as not needing to run it... you really should run your own ipfs node. It's the only way to guarantee that your content will remain available when people want it. The cache life on IPFS seems to be about 8 hours, though, which is pretty amazing, but it's no substitute for actually being part of the network.

That said, you might be able to find public nodes that are writable. You'll have to do a google search for that, but I'm absolutely certain they're out there.

You might also want to look at channels like Steemit for people who are actively working on IPFS projects. I've had good luck there. A lot of answers about IPFS, Swarm, Web3, and Dapps in general.

Oh, and to test if a node is writeable, try this:

<form action="http://[domain_name]:[port_number]/ipfs/api/v0/add" enctype="multipart/form-data" method="post">
    <input type="file" name="image" accept="image/*"/>
    <input type="submit"/>
</form>

Good Luck!

Yitzhak
  • 551
  • 6
  • 12
  • When you say "The cache life on IPFS seems to be about 8 hours"... does that mean IPFS will only host the file for that long? If so, is there a way to make it last longer? Or, ideally, as long as you want it? – razorsyntax Jul 11 '18 at 21:16
  • 1
    @razorsyntax you can pin content to keep it online as long as you wish: https://docs.ipfs.io/reference/api/cli/#ipfs-pin – Federico Ponzi Oct 03 '18 at 09:14
  • 1
    @razorsyntax: The 8 hour estimate was about the public IPFs gateway (https://ipfs.io/), when you run your own node content will be kept until you remove it – or on `ipfs repo gc` if you haven't pinned it. – ntninja Nov 07 '18 at 18:27