Textile makes it easy to run IPFS peers in your mobile apps

AirSecure, Notes, and Photos mobile apps, each use Textile to manage IPFS peers.

Does Textile Photos run an IPFS peer on every user’s mobile device? We get the question often, so we know the answer isn’t obvious. The answer is, yes. At Textile, we use IPFS because it is helping us get closer to our goal of helping people truly own their digital data. We believe that the stack of protocols available in IPFS can help all developers rethink the way they treat data on the web, and in particular, can help us use encryption, permissions, and decentralized sharing to put data ownership into the hands of people.

Big ideas aside, running IPFS on mobile introduces challenges to any app developer, such as deciding when and how it should run, how to efficiently transfer data in a mobile environment, and how to link the behaviors of the IPFS node to the native device APIs (e.g. background and foreground events). Over the past months of working with IPFS in Textile Photos, we’ve been tuning and improving our approach to launching, managing, and using IPFS in our mobile app. Now, it’s ready for any developer to build on that work.

To make IPFS run easily in our mobile apps, we’ve combined some scaffolding with a bunch of custom APIs into the Textile developer framework. Our first release of the framework, the React Native SDK, lets an app developer install and manage an IPFS node directly in their app with just a couple lines of code. Soon, our Objective-C (iOS) and Java (Android) libraries will make it accessible to even more developers. Here, I just want to walk through some of the simple steps to get IPFS into your mobile app using Textile.

Getting started

Assuming you have a React Native app setup, you should be able to simply add the following to the top of your app setup file. You can see examples of where this is run in one of the existing demo apps (e.g. Single Screen Boilerplate, Notes, AirSecure).

import Textile from '@textile/react-native-sdk';
// Setup will prepare the environment
Textile.setup();

You may be familiar with the IPFS setup steps (e.g. ipfs init) that result in a new peer-id, private key, etc. With Textile installed in your app, initiating Textile will handle setting up a new IPFS peer on the device, all in one simple line of code:

// A single line to create the Textile node and embedded IPFS peer
Textile.nodeCreateAndStart();

Simple controls

From there, you can let Textile manage the starting and stopping of your node based on phone behaviors, or you can take direct control. These methods enable a developer to quickly launch IPFS in a mobile app and restart it whenever new media needs to be stored or retrieved. While simple to use, there is actually a lot of complexity going on under the hood here. From bootstrapping peer connections, to fetching content updates, to processing network queries in the background. All of this is abstracted away into a simple start/stop API that is easy to use:

import { API } from '@textile/react-native-sdk';
// Stop an already started node
API.stop();
// Start it back up later
API.start();

Request data on IPFS

Decentralized data can benefit mobile apps and their users already (e.g. censorship resistance). So we’ve made it easy to request any IPFS hash (and path) using the IPFS protocol.

import { API } from '@textile/react-native-sdk';
// Grab an image off of IPFS
const hashPath = '
QmTgtbb4LckHaXh1YhpNcBu48cFY8zgT1Lh49q7q7ksf3M/raster-generated/ipfs-logo-text-512-ice.png';
const imageData = API.dataAtPath(hashPath);
// Display that image using React Native Image
<Image
style={{width: 150, height: 150, resizeMode: 'cover'}}
source={{uri: 'data:image/png;base64,' + imageData}}
/>

Boilerplate apps

Textile offers a few simple boilerplate repos for developers to clone, build, and tear apart. The first one, react-native-boilerplate, provides a single-screen React Native app that packs in quite a few Textile & IPFS commands (including those above) to simply and easily show what is possible.

Already have a more complete app idea in mind? Grab the advanced boilerplate, for multi-screen support, state management, Textile event management, and more. To give you an idea of what can be done quickly and easily with these boilerplate apps, check out the AirSecure app or Textile Notes app.

Why add IPFS or Textile to your mobile app

There are a number of reasons to add IPFS or Textile to your mobile app, both technical and not. Our opinions are biased obviously, but we believe IPFS is forging the way towards better systems of media and data exchange on the Internet. But the architecture of the IPFS network and how Textile uses it have some important side-effects. Here are some of our top reasons for being so optimistic.

Content Addressing

A content addressed approach to information retrieval on the Internet opens up a new way to think about, not only data availability, but data ownership as well. We can build new kinds of apps and services that don’t need to think about building silos of their own data when they can collaborate across an interlinked network of information created by many apps. That’s an exciting system to build applications on.

Decentralized Networks

At the root of IPFS are a handful of mechanisms that allow nodes on the network to retrieve information from other peers, even when not directly connected to the original provider. This gives rise to new benefits, like being able to create apps that are fully functional in small isolated subnets, cut off from the greater Internet.

Encrypted & P2P

Related to the decentralized nature of IPFS, Textile helps developers use encryption for all data storage and transfer. Encryption and permissions systems mean that apps can build secure chat and sharing features into their apps easily. In Textile Photos, you can see these two primitives used many times across the app.

Censorship Resistant

Components like those above have made the IPFS network resilient to censorship attempts. Examples include the Uncensorable Wikipedia in Turkey and the vote organizing in Catalonia. Censorship resistance and privacy through encryption may allow developers to build the future of journalism/reporting applications, knowledge platforms, voting applications, and more.

Personal Data Sovereignty

We’ve previously written about why we think this is important. Data is becoming an extension of our physical existence. Voting, dating, shopping , health are just a few examples of where humans and the important (and often private) information they create is being captured in digital data. We need to build technologies that let individuals own that data, forever. We are building our developer tools to help make that future a reality. Using Textile and IPFS, developers can start building apps that take the first steps.

There are many others, including new ways to think about GDPR, building secure patient or student services, connecting to blockchains, etc, but we’ll cover each of those in more depth later.

Next steps

If you’d like to try it out, grab one of the boilerplate apps and play around with your first mobile app with embedded IPFS peer. Or, grab the code for one of the existing apps released on Textile, including Textile Photos, AirSecure, and Textile Notes.

We have a great community of builders on our developer slack channel, so jump in if you have any questions about using IPFS in your mobile apps.