Deep Dive on Filecoin & IPFS use cases in the Solana ecosystem
In this article, we will deep dive into how Filecoin can be used in the Solana Ecosystem. The article will be developer-centric, but if you are an NFT artist, we have a lot of things in store for you as well :)
The article will be structured in the following sections
- What are Filecoin and IPFS, and what problems it's solving in the blockchain ecosystem?
- Use cases
– Using IPFS to store NFTs and metadata of Candy Machine V2
– Using the various IPFS libraries for storage in your dapps
– Deploying and hosting dapps on IPFS - Awesome Developer Tools
– Pinata
– Fleek
– Web3.Storage
– NFT.Storage
We will have tons of resources + code snippets in the articles to make it easier for Solana devs to integrate IPFS into their projects. Let’s begin, shall we?
Filecoin and IPFS
Protocol Labs is the Research and Development Lab which proposed the whitepaper of IPFS back in 2014, and then, later on, Filecoin launched its Mainnet in 2020. Currently Protocol Labs, Filecoin and IPFS exist as different organizations.
Interplanetary File System (IPFS)
IPFS is a distributed system for storing and accessing files, websites, applications, and data. The core concept is to have a distributed storage system rather than a decentralized one to make it better. Considering even if we shift to multiple planets, a distributed storage network will help in getting better access to our files and folders.
Filecoin
Filecoin is a peer-to-peer network that allows anyone to store and retrieve data on the internet. Built-in economic incentives ensure that files are stored and retrieved reliably and continuously for however long a user specifies.
Filecoin includes a blockchain and native cryptocurrency (FIL).
Storage providers earn units of FIL for storing files. Filecoin’s blockchain records transactions to send and receive FIL, along with proofs from storage providers that they are storing their files correctly.
While interacting with IPFS does not require using Filecoin, all Filecoin nodes are IPFS nodes under the hood.
Fun fact Chingari uses Filecoin.
Use cases
Using IPFS in Candy Machine V2
If you are a Solana Buildoor, you might already know what a Candy Machine is. If you don’t, Metaplex has created this easy to setup NFT Distribution program called Candy Machine.
Candy Machine Version 1 is now deprecated and Candy Machine V2 is used currently. One can easily integrate IPFS into the Candy Machine by changing the config file.
For setting up your Candy Machine, you require the NFT Assets ( images + metadata ), a config file and some Solana to get it deployed. The Metaplex Documentation explains very well how to set up one.
For using IPFS as storage for your assets, you just need to keep “ipfs” for the “storage” value in the config.json file. Here is the documentation to set up the configuration file.
Here is a sample config.json file that will use IPFS for the storage of your assets.
{
"price": 1.0,
"number": 10,
"gatekeeper": null,
"solTreasuryAccount": "<YOUR WALLET ADDRESS>",
"splTokenAccount": null,
"splToken": null,
"goLiveDate": "25 Dec 2021 00:00:00 GMT",
"endSettings": null,
"whitelistMintSettings": null,
"hiddenSettings": null,
"storage": "ipfs",
"ipfsInfuraProjectId": <ADD_PROJECT_ID>,
"ipfsInfuraSecret": <ADD_SECRET_KEY>,
"nftStorageKey": null,
"awsS3Bucket": null,
"noRetainAuthority": false,
"noMutable": false
}
Pinata and NFT.storage are also developer tools built upon IPFS and can be added as the value of “storage”. I have explained Pinata and NFT.Storage in the later parts of the article.
IPFS Libraries for your Dapps
You can’t store larger files in the smart contract itself as it will become quite expensive and will be a tedious job to perform, thus you can simply upload the larger files on IPFS and then store the CID in the smart contract.
Here are the JavaScript libraries you can use in your Dapps wherever a need arises for storage. This way you don’t need to rely on any centralized server to hold your assets, and your application can be truly decentralized.
An overview of the Dapp
Here is a code snippet for storing data on IPFS using https://js.ipfs.io/
const node = await IPFS.create()const data = 'Hello, Buildooor'const results = node.add(data)for await (const { cid } of results) {
// CID (Content IDentifier) uniquely addresses the data
// and can be used to get it again.
console.log(cid.toString())
}
Output: QmQHXWBEM4xGySEcxf7MdaeKb453zAvkF8oRXRVQ9tqN9E
Code Snippet for fetching data
const node = await IPFS.create()const stream = node.cat('QmQHXWBEM4xGySEcxf7MdaeKb453zAvkF8oRXRVQ9tqN9E')
let data = ''for await (const chunk of stream) {
// chunks of data are returned as a Buffer, convert it to string
data += chunk.toString()
}console.log(data)
Output: Hello, Buildooor
Deploying and Hosting dapps on IPFS
After creating your fancy web app in any of the tech stacks like reactjs, nextjs, vue etc you can deploy and host the app on IPFS using Fleek. Fleek is pretty much similar to Vercel/Netlify, where you just connect your Github and it builds and deploys the project.
How to deploy your web app on Fleek?
- Sign up on https://fleek.co/
- Click on Add New Site on the top right.
3. Connect your GitHub
4. Select the repository, choose the network as IPFS, add in your build commands and environment variables (if any) and hit Deploy
That’s it !! Now your website is deployed on IPFS !! Go grab some cake !!
Awesome Developer Tools
There are a lot of Developer Tools which make life easier for the glass chewers to integrate IPFS and Filecoin. Let’s check out what functionality they provide and how to use them.
Pinata
Pinata is this easy to use tool which helps in pinning files and folders on IPFS. You can use it to store NFT Media, or any other files you want to store on IPFS. It has a simple UI as well as APIs to integrate it into your dapp.
How to use Pinata?
- Go to their website https://www.pinata.cloud/
2. Create your account, a free account gets you storage of 1 GB, if you require bigger storage space, you will need a premium account.
3. Once logged in, you can simply upload your file/folder and after uploading it will give you a CID ( Content Identifier ) to the file. Anyone who has this CID can access your file/folder. IPFS is a public network.
And that’s it. Now you can access the file using the CID.
ipfs://<Insert your CID here>
I uploaded an example here.
You can even use Pinata APIs to pin your files, the documentation to use their APIs is provided here.
Fleek
As explained earlier in the article, you can use Fleek to deploy your web apps on IPFS. Fleek has more services to provide. Space Daemon packages together IPFS, Textile Threads/Buckets, and Textile Powergate (Filecoin*) into one easy to install background service. Space is the next evolution of the Cloud, where users can interact with apps fully private, p2p, and control their own data.
Some of the features of Space Daemon are
- Fully Private file upload via encrypted textile buckets.
- Peer to Peer file sharing selectively with other people and/or within teams.
- Identity solution to enable users to be anywhere from fully anonymous to having as many identity associations as they want.
- More….
Here is the documentation through which you can read more about utilising it in your project.
Web3.Storage
It's another tool which provides you with an API token through which you can upload data on IPFS. The instructions are easy to follow and are well documented here.
The documentation consists of pretty much everything a developer will require to do for the project.
One can easily follow the documentation and integrate Web3 Storage in their project using the following code snippet.
import { Web3Storage } from 'web3.storage';
// Construct with token and endpoint
const client = new Web3Storage({ token: apiToken });
All the functionalities get available to you once you run the constructor. There is even a Go lang library.
NFT.Storage
NFT.Storage is a side product of Web3.Storage specifically for the NFTs Metadata.
Once you login, the user interface is pretty much intuitive. Its made easy to use so that NFT artists who lack the development experience can also use it without any difficulties.
One can simply drag and drop a folder of all the NFT assets and it will get uploaded. They also have an API through which the developers can call its functionalities.
Here are the docs through which you can upload your Candy Machine Assets on NFT-storage, I explained it earlier in the article as well.
Conclusion
In this complete article, we went through multiple ways how IPFS and Filecoin can be integrated into the Solana Ecosystem. Thanks to all the awesome developer tools which make things easier for the developers. The libraries and their documentation make glass chewing easy.
So after understanding and getting all this new knowledge regarding the tools, what are you waiting for, go open your IDE and start coding !!