How to build a decentralized website on Filecoin Network?
About Filecoin
Filecoin is the largest decentralized storage network in the world, which allows users to store, request and transmit data through a verifiable market. Filecoin is entirely open source. The protocol runs on a reliable system that combines Proof of Space-time (PoSt) and Proof of Replication (PoRep), which provides a solid foundation for storing the world’s most valuable data sets, minimizes economic barriers, and allows users to enjoy its network capabilities. IPFS, a Web3 file system in this system, allows devs to access data on the network.
Build a Decentralized Website via IPFS
Decentralizing a website means obtaining data from the nearest data source, which can be completed via IPFS.
First, generate a static website using Hugo, and upload it to the IPFS system:
hugo --gc --minify
npx ipfs-deploy public -p pinata -d cloudflare
The first command calls Hugo to generate a new directory, called “public”, which contains all the pages of the website. The following command calls “ipfs deploy”, which adds a directory (“public” in this example) to the “pin service” and updates it to the DNSLink in the DNS domain name service we define.
What is the “pin service” here?
“pin” service is an online service that runs the IPFS daemon process and is usually a gateway. This online service ensures that the content of the website will not be lost from the website. Some people may worry about whether this means that everything depends on this online service. Is this a kind of centralization?
In fact, running IPSF daemon locally and adding the website content to a local server could solve this issue. We should do these two things both.
What is the “DNSLink”?
DNSLink is actually a text record that maps a domain name to an IPFS hash, which enables the IPFS system to access the website content.
IPFS Hash can not be displayed to the users directly, so some other services may be needed:
“Pinata” provides 1GB of space freely for users to pin. After registration on its website, we can obtain “api key” and “secret api key”. And “ipfs deploy” will be available after setting 2 environment variables:
IPFS_DEPLOY_PINATA__API_KEY=<api key>
IPFS_DEPLOY_PINATA__SECRET_API_KEY=<secret api key>
The DNS service of Cloudflare is also necessary. Here is the guide to using IPFS gateway on Cloudflare:
For example, if the domain name of the website is http://example.com We need to add a CNAME record to the root directory of “cloudflare-ipfs. com” so that the website can be parsed by the gateway of Cloudflare.
The combination of Pinata and Cloundsquare enables the website content to be accessed as soon as possible, and also enables the update of the website content to be completed as soon as possible.
We also need to set some environment variables to improve the configuration of “ipfs deploy”, so that we can automatically update the records of DNSLink:
ipfs-deploy -p pinata -d cloudflare
In this way, the website will be “pinned” to Pinata, and the DNSLink on Cloudflare will also be updated.
So far, the website is completely decentralized.
Filecoin lead the data economy in the future
IPFS and Filecoin are complementary systems. IPFS allows users to store and transmit content through peer-to-peer networks. According to the cloud-storage market report, the size of the global cloud-storage market is expected to grow from $50.1 billion in 2020 to $1373 billion in 2025.
IPFS and Filecoin have transformed the blockchain network from a resource-consuming to a resource-contributing, providing a new development direction and a more solid infrastructure.
Filecoin, as the value equalizer in the whole system, will be more and more valuable in the future with the steady development of the IPFS system.
New to trading? Try crypto trading bots or copy trading on best crypto exchanges