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?

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

Comments

6

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!

3 Comments

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 you can pin content to keep it online as long as you wish: docs.ipfs.io/reference/api/cli/#ipfs-pin
@razorsyntax: The 8 hour estimate was about the public IPFs gateway (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.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.