GUN: Create a Decentralized Chat App with GUN and IPFS

Learn how to create a decentralized chat app with GUN and IPFS.

What is GUN?

GUN is a series of open-source tools that includes a decentralized database service that uses peer-to-peer networks to store relational databases and their associated information. GUN can be used to build decentralized versions of hundreds of popular websites, like Youtube, Github, Reddit, and Slack.

Read below to learn how to create a decentralized chat app with GUN and IPFS.

Prerequisites:

1. First, we need a Filebase IPFS bucket.

To do this, navigate to console.filebase.com. If you don’t have an account already, sign up, then log in.

2. Select ‘Buckets’ from the left sidebar menu, or navigate to console.filebase.com/buckets.

Select ‘Create Bucket’ in the top right corner to create a new bucket.

3. Enter a bucket name and choose the IPFS storage network to create the bucket.

Bucket names must be unique across all Filebase users, be between 3 and 63 characters long, and can contain only lowercase characters, numbers, and dashes.

4. Next, download and install S3FS-FUSE on a Linux or macOS system.

5. Set up an Access Key file for use with S3FS-FUSE.

Set up a credentials file for S3FS at ${HOME}/.passwd-s3fs. You will need to save your Filebase Access and Secret keys to this file and give it owner permissions. You can do so with the following commands:

echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > ${HOME}/.passwd-s3fs

chmod 600 ${HOME}/.passwd-s3fs

ACCESS_KEY_ID is your Filebase Access key, and SECRET_ACCESS_KEY is your Filebase Secret key. For more information on Filebase access keys, see here.

6. Mount your bucket.

You can mount a Filebase IPFS bucket with the command:

s3fs mybucket /path/to/mountpoint -o passwd_file=${HOME}/.passwd-s3fs -o url=https://s3.filebase.com

  • mybucket: name of your Filebase bucket

  • /path/to/mountpoint

7. Now, navigate into the mounted Filebase bucket.

cd /path/to/mountpoint

8. Then, clone the Github repo for the Gun decentralized chat app:

git clone https://github.com/fireship-io/gun-chat.git

9. Next, install the project’s dependencies:

cd gun-chat

npm install

10. Run the app with the command:

npm run dev

11. Navigate to localhost:5000. Your app will appear and look like this:

12. Enter a username and password, then select ‘Sign up’.

13. Open another browser tab at localhost:5000, and create another user with a different name and password, then select ‘Sign up’ again.

Enter some chat messages in both windows to see the chat propagate in both windows!

You now have a decentralized chat app that uses a decentralized database, GUN, that is pinned on IPFS!

If you have any questions, please join our Discord server, or send us an email at hello@filebase.com

Last updated