Lens Protocol: Build a Decentralized Social Media Network Stored on IPFS
Learn how to build a decentralized social media network stored on IPFS.
What is Lens Protocol?
Lens Protocol is a smart contract based social network protocol using the Polygon blockchain network that enables developers to build decentralized social media websites that use smart contracts for each transaction on the website.
Read below to learn how to build a decentralized social media network stored on IPFS.
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 side bar 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. Open a terminal window. Then, 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/mounted/bucket
8. Create a new folder for your project, then navigate inside that folder:
mkdir decentralized-social-media
9. Clone the GitHub repository for this project:
git clone –branch starter https://github.com/Olanetsoft/decentralize-social-media-app-with-lens-protocol.git decentralized-social-media
cd decentralized-social-media
10. Install and start the app with the command:
npm install && npm run build && npm start
11. Navigate to localhost:3000. You will see the default app screen:
localhost:3000. You will see the default app screen:
By default, this app shows only one profile that is pre-configured. We’ll need to edit the API to fetch all profiles currently built using the Lens protocol.
12. Open the pages/api/api.js file and replace the existing code with the following:
pages/api/api.js file and replace the existing code with the following:This piece of code imports the createClient module from urql that is used to send GraphQL requests to the project’s API, then it sets up a client to make a request to the Lens protocol API. Finally, it sets up the getProfiles endpoint to retrieve current Lens Protocol profiles.
13. Next, open the index.js file and replace the existing content with the following code:
index.js file and replace the existing content with the following code:This code creates the variable profiles that is used to save retrieved profile data, then validates a profile’s value after the fetchProfile function is returned.
14. Navigate into the components directory, then open the profiles.js file. Update the file’s content with the following code:
components directory, then open the profiles.js file. Update the file’s content with the following code:15. Open the next.config.js file and replace the content with the following:
next.config.js file and replace the content with the following:16. Save all changes. Then, start the app in development mode using the command:
yarn dev
You will now see the following screen at localhost:3000:

17. If you click on a single profile, you will get an error 404 page, so let’s fix that. Open the pages/api/api.js code and add the following code:
pages/api/api.js code and add the following code:18. Then, open the pages/profiles/[id].js file and insert the following:
pages/profiles/[id].js file and insert the following:19. Now, if you click on an individual profile, you’ll see the user’s information:

20. Lastly, let’s add functionality to view the user’s publications. Open the pages/api/api.js file again and add the following code:
pages/api/api.js file again and add the following code:21. Then, replace the content in the [id].js with the following:
[id].js with the following:22. Now, you can click on a user’s profile and view their existing publications within their profile:

23. From here, you can style the website using TailwindCSS, or play around with comment and following functionality.
Last updated
Was this helpful?