A few days ago I had an idea. What if I could have my home server automatically download my photo library from iCloud and sync the changes to Sia using the recently-released SiaSync tool? And what if I could access and browse these files on other devices, like my iPhone or iPad?

First, though, I would need a way to upload and download Sia files from iOS. Although there is a third-party mobile app available for Sia, it is exclusive to Android and requires running a full node on the device. Was there a better way?

I contacted Nebulous core developer Luke Champine to find out. As it turned out, he too was interested in writing mobile apps for Sia using his us project! We quickly began putting together a simple app, with Luke handling the Sia-specific code and us bindings, and myself handling the UI/UX. (We also collaborated on this blog post.) By the end of the weekend, we were giddy with excitement, because we had succeeded in uploading and downloading a file, talking directly to Sia hosts from a real iPhone, without a full node. See for yourself:

So, what’s happening behind the scenes here? What’s up with the QR code, and what is a “Shard Server?” And why does it take so long to upload a tiny image? Read on to learn the answers. If you want to jump straight into the code, though, you can find the GitHub repo for the app here: https://github.com/DangerCZ/SiaUs-iOS

How it Works

We begin by scanning a QR code that contains a Sia file contract. We do not form the contract on the device itself; at least for now, we need to get our contracts from an external source. Check out the us-bindings repository for details on how to acquire a contract and convert it to a QR code.

The contract tells us the public key of the host we’re communicating with, but not its IP address. Hosts only announce their IP address on the Sia blockchain, and we don’t want to store the whole blockchain on our phone. This is where the shard server comes into play. Much like a DNS server, this server watches the blockchain and provides a public lookup table for host IP addresses. Anyone can run a shard server; in the demo, we connect to Luke’s instance.

Thanks to the new protocol introduced in Sia v1.4.0, this is all the information we need to upload and download! The mobile app uses the us filesystem code, compiled for iOS using gomobile . Since us handles all the Sia-specific details, mobile app developers can focus on what they do best.

Lastly: why is the upload slow? This is because Sia has to upload at least 4 MiB at a time, so we have to pad our photo out to 4 MiB before uploading. There are plans to improve this limitation in later versions of the Sia protocol, but for now we have to work around it. For example, we could wait until the user has “uploaded” 4 MiB of photos before we actually send anything to the host. Or we could upload asynchronously, like many cloud storage apps do, to make the delay less noticeable.

Future Work

The demo app uses a single contract, which means our data is at the mercy of a single host. A real app should use many contracts and store its files redundantly. Additionally, since us does not automatically renew your contracts, the app developer is responsible for this. Apps should display a warning notification when contracts are at risk of expiring.

Both of these issues could be solved by a contract management service. Like shard , this would be an external server (run by you or a third party) that handles forming and renewing Sia contracts. The mobile app could then download a set of contracts directly from the server, removing the need for QR code scanning, and query the server regularly to receive renewed contracts. Perhaps the app developer could even provide contracts directly via in-app purchases, giving the developer a source of revenue.

Conclusion

We have shown that it is possible to write mobile apps that store and retrieve data on the Sia network. While our demo app was written for iOS, the us bindings are compatible with Android as well. We hope that this demo inspires other mobile developers to create apps that are much more sophisticated than our simple proof-of-concept. :)