# How to use IPFS for governance
# What is IPFS
In Web 2.0, a web application consists of a backend and a frontend. The backend is the server where the database and the application logic run. The frontend consists of the user interface, what the user sees, and communicates with the backend via API calls. Usually, these are stored by the developer of the application in centralized servers.
In the decentralized world, we can consider Cosmos SDK chains as a backend of our decentralized applications (Dapps). The blockchain lets us store and retrieve data. Dapps usually have a frontend as well, and that frontend can be stored in a centralized entity (AWS, GitHub Pages) or, in order to be 100% decentralized, use a protocol like IPFS.
IPFS is a distributed system for storing and accessing files, websites, applications, and data.
This means that IPFS allows you to store your frontend in a decentralized manner.
You can find more information about how IPFS works in their documentation (opens new window).
In this tutorial, you will learn how to store files and websites on IPFS.
First download and install IPFS, find the instructions for your OS here (opens new window).
Verify you have a working installation by running the following command:
Which for instance returns:
# Submit a file
To make a file available on IPFS, you need to make it available to an IPFS node. This can be a local IPFS node or a remote one. In this tutorial, you will use a remote node.
For Cosmos chain governance, you want to store the metadata on IPFS nodes.
Create a file called
metadata.json with the following content:
Add the file to your IPFS node:
Which for instance returns:
add you have pinned the file (opens new window) to the node, stopping it from being eventually pruned.
The content identifier (CID) of the file is
Qmbct5cv1SxMpEYCpNEvZnQ5TkN1rk7KyTmV95nbsrbLiR. This is the CID that you will use to retrieve the file from IPFS.
Verify the content of the file by running:
At this point, you can start your local IPFS node:
The file becomes available on IPFS. You can easily access it via
https://ipfs.io/ipfs/<cid>, in your case
Note that as soon as you stop the node, it is possible that after a while, the file will not be accessible on the network. This is because only your node has pinned the file, other nodes may delete the file depending of their retention policy.
As you want to store the metadata permanently, without running your IPFS own node (for the scope of this tutorial), you want to pin it to a remote node, using a pinning service (opens new window).
# Pinning services
Pinning services are services that pin files on their nodes, making them available on the network, without having to run your own node.
For this tutorial, you will use Web3.storage (opens new window), a pinning service provided by Protocol Labs, the main developers of IPFS. Feel free to use any other pinning service you prefer, such as Pinata (opens new window), Infura (opens new window), etc.
First, create an account on Web3.storage (opens new window) and get an API token (opens new window). With Web3.storage, you need to request access to the pinning API, or you can upload the file directly from the interface.
web3.storage as a remote service:
Make sure your node can serve the file when the Web3.storage server looks for it:
Now you can pin the file to the remote node:
Your file is now pinned to the remote node.
# 🎉 Congratulations 🎉
By completing this tutorial, you have learned how to use IPFS for storing files, notably for proposal metadata.