Building a Decentralized Chat Client Using IPFS

Dether Wallet
Jun 7, 2019 · 5 min read

This is the latest in a series of updates on the upcoming version of the Dether app. In this post, find out what it takes to build a decentralized in-app chat using IPFS.

What is Dether?

Dether is a peer-to-peer, crypto-to-cash marketplace where users can buy and sell crypto (like ether, DAI, MRK, REP, and others) for and with over thirty different currencies in 140 countries. Crypto buyers can geolocate Dether sellers around them on the Dether map, and then contact them to set up trading conditions and a trading location. Buyers receive their crypto using a QR code while sellers are given cash directly. All transactions are visible on the “history” tab of the Dether app. Users can also view businesses around them accepting crypto as payment.

Dether is available for iOS, Android, and as a PWA.

Dark blue icons indicate crypto sellers, while turquoise icons represent businesses accepting crypto.

Why have an in-app chat?

Because Dether is a peer-to-peer cash-to-crypto marketplace, having a way to chat with potential Dether buyers and sellers is a fundamental part to the inner workings of the Dether app. Buyers need to be able to contact potential sellers, and sellers needs a way to reach out to buyers to agree on trading conditions and their commission fees.

In the current version of Dether, we’ve been using Telegram as a chat solution — users have had to input their Telegram username that was then listed in their seller profile on the Dether map (potential buyers also had to use Telegram to connect with these sellers). Although Telegram is widely used in the crypto space, many users delete their account or edit their username. As a result, a seller may be listed on the Dether map but impossible to reach him.

Through traveling and research, we also learned that Telegram is not widely used in some countries, like in Haiti or parts of Latin America, so it was important that we created a way to contact users without having to leave the app or download another.

Because users’ privacy matters, we wanted to be sure to implement an alternative to a central server to host or route messages, like those used by Facebook and WhatsApp. Creating a chat system is no easy feat. Here’s how we’re doing it:


Using an IPFS solution

IPFS, which stands for Interplanetary File System, is a peer-to-peer file sharing system. Unlike client-server relationships, in which data is stored in centralized servers, IPFS uses distributed hash tables (DHT) to spread the data across a network of computers.

When a file is added to IPFS, it’s given a unique fingerprint called a cryptographic hash, and the content is then stored behind this unique hash. Network nodes only store content of interest, and with the help of indexing information, is able to figure out who is storing what.

Benefits of IPFS include the possibility of distributing high volumes of data with high efficiency, resilient networks, and a store of every version of a file, making it simple to set up resilient networks for data mirroring.

A demo of the IPFS system

Despite the exciting potential of an IPFS solution, there are still a number of questions to consider regarding IPFS. As it’s very new territory, IPFS isn’t an “out-of-the-box” solution that’s ready to be used and required some tweaking and fine-tuning in order to implement the solution in the Dether app.

We researched many IPFS libraries and decided to use OrbitDB as a base layer for our in-app chat. OrbitDb is an excellent project, and even has a working peer-to-peer chat example with impressive speed using the experimental ‘pub-sub’ feature of IPFS. This allowed us to set up unique channels between users through the app and host a live chat system.

With this in order, we still needed a way to persist data when both the message sender and receiver are offline and no one is hosting the message.


Persisting offline messages

Much like sharing a file on BitTorrent, unless someone is actively sharing (or seeding) a file on IPFS, without a central host, the file can’t be found. So when a user goes offline after sending a message, the message is no longer hosted. To solve this, we use a swarm of IPFS nodes acting as a “pinning” service allowing the message to be persisted (pinned) and discoverable by the receiver from any of the hosting swarm nodes. Each message that is sent is sent using both Orbit chat instantly and also to a pinning service to save the chat history.


Message encryption

We also wanted to encrypt the messages end-to-end for added privacy using PGP encryption, because IPFS channel messages are publicly viewable. One issue we wanted to resolve was how to find a peers PGP key in order to encrypt the user’s message without a central database of keys. Initially, we tried to solve this with a complex four-part “key-exchange” handshake upon starting any chat; unfortunately, this proved slow and not useful for cross device log-in, where the user wouldn’t have their own keys locally again.

Later, we opted to use IPFS itself as an index store of all passworded PGP keys so they could be available and retrieved quickly for any new chat channel. Each message sent peer-to-peer is encrypted before sending and decrypted upon receipt by the receivers own private key.

What’s our user experience vision?

When it comes to building a decentralized solution, it’s important to balance a smooth user experience and a fully decentralized, secure feature.

As a user, the only element you’ll need to use the Dether chat will be your Ethereum address——no need to create an account with an email address. When creating your Dether account, you’ll have the choice to either create a wallet or import one (using your private key or your backup phrase).

Once you’ve done that, you’ll be able to locate sellers on the map, click on their profile, and chat directly with them. Each chat account is directly linked to an Ethereum address. And if you wish to speak to someone who is not located on the map (for example a friend who has the Dether app), you’ll be able paste his or her Ethereum address and then talk to him her.

We’re still hard at work on the user interface, but we envision it as a simple but accessible way to get in contact with those looking to sell cryptocurrency.

Are you looking forward to the new, in-app chat? Leave us your thoughts below!

Dether Talk

Buy and Sell Crypto, wherever you are in the world

Dether Wallet

Written by

Buy and sell crypto, wherever you are in the world

Dether Talk

Buy and Sell Crypto, wherever you are in the world

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade