With the following code snippet, you can add blockchain-based data storage with one of the leading data storage solution alternatives in Web3:
const response = await Moralis.EvmApi.ipfs.uploadFolder(options);
If you are familiar with Moralis, you can use the code snippet above to utilize IPFS and add blockchain-based storage to your Web3 project. However, if you haven’t worked with Moralis before, the last section of today’s article will help you learn how to correctly implement the above line of code. Now, if you’d like to tackle the tutorial, you must first activate your free Moralis account!
Overview
Every blockchain project is unique and requires individual consideration. However, these projects should always aim for decentralization, transparency, security, and immutability. After all, these are the core characteristics of Web3. Moreover, all Web3 projects should ideally use blockchain-based data storage solutions. Now, if you are a Web2 dev looking to join the Web3 revolution, knowledge about blockchain-based storage system solutions and how to use them is one of the essential aspects you should explore further.
In today’s article, you’ll have a chance to learn all you need to know about blockchain-based file storage solutions and how to start using them in your projects. That said, let’s take a look at the article’s outline:
- First, we’ll ensure you all know what blockchain storage is and what kind of data blockchains can store. This foundation will help you understand blockchain-based data storage, which we’ll also examine in more depth.
- Then, we’ll take a closer look at how documents and files go together with a proper blockchain-based cloud storage system.
- Next, we’ll cover some of the leading companies offering blockchain-based file storage.
- Last but not least, you’ll have a chance to take on our tutorial, which will teach you how to implement the code presented at the outset of this article.
Blockchain Storage – What is it?
Blockchain storage can refer to blockchains themselves; however, the term usually refers to a decentralized storage solution. Furthermore, this kind of storage doesn’t have a single point of failure and enables users to truly own their data. Moreover, blockchain storage is typically directly or indirectly connected with blockchain technology. In many cases, it utilizes this new innovative tech or, at least, works hand-in-hand with it.
It’s important to note that blockchains are, at their core, unique kinds of databases. Hence, referring to them as “blockchain storage” is technically legit. However, a proper blockchain-based storage system focuses on storing a wider range of data, including extensive pieces of information (images, videos, documents, websites, applications, etc.).
Another commonly used term for blockchain storage is “Web3 storage”. In our opinion, the latter may be more suitable as it is a more general term. Further, it’s pretty suitable because several blockchain-based document storage system solutions or blockchain storage solutions do not actually store data on the blockchain. Yet, they meet the decentralization and transparency standards, and, therefore, they are proper Web3 storage solutions. Moreover, unlike centralized cloud storage providers (Google Cloud, Dropbox, OneDrive, etc.), Web3 storage companies do not have a single point of failure and can ensure privacy transparently.
Now that you know what blockchain/Web3 storage is, it’s time you learn what kind of data a blockchain can actually store.
Feel free to dive deeper into the “what is blockchain storage?” topic with one of our previous articles.
What Kind of Data Can Be Stored in a Blockchain?
The two most popular blockchains are Bitcoin and Ethereum. While the former was the first blockchain, Ethereum took Web3 to the next level. After all, Ethereum was the first so-called programmable blockchain supporting smart contracts. This expanded the kind of data that can be stored in a blockchain. However, the limitations of blockchains are still very much present, and, therefore, blockchains can’t store large files.
After all, you might have experienced network congestion and exorbitant transaction fees. If those issues occur with small chunks of data, imagine the problems that would occur if blockchains had to process large files. All in all, it’s still technically and economically impossible to store large files on the blockchain. Thus, the data that devs can store in a blockchain is limited to transaction hashes, and properly compiled on-chain programs (smart contracts). In fact, to add more clarity, let’s look at how NFTs (non-fungible tokens) are stored.
Should You Use a Blockchain-Based Storage System for NFTs?
You probably know that NFTs come with NFT-representing files and metadata files. While most folks think these files are stored on a blockchain, that is not the case. NFT-representing files are typically larger files, including images, audio files, or even videos. On the other hand, metadata files are usually JSON files that are not that large. Yet, it is still not economically feasible to store them on a blockchain. Moreover, the only thing stored on a blockchain for a particular NFT is the NFT’s smart contract. When deployed, the latter mints related NFT(s) and is also responsible for governing the transactions of its NFT(s) and adequately assigning ownership.
Furthermore, smart contracts include URI links to the metadata files, and inside the metadata files are the links (URLs) to the NFT-representing files. Hence, NFT devs must decide where to store metadata and NFT-representing files. Ideally, they’d use a reputable blockchain-based cloud storage system:
What is Blockchain-Based Data Storage?
Blockchain-based data storage is just another term for “blockchain storage” or “Web3 storage”. With “blockchain-based”, the term more clearly indicates that data is not necessarily stored on the blockchain but that these storage solutions use blockchain or are designed to work with the blockchain. Nonetheless, as we proceed, you’ll learn that the current leading blockchain-based document storage system is actually not using blockchain. However, due to blockchain-like cryptographic principles and a high level of decentralization, it is more often than not categorized as a blockchain-based file storage solution. In fact, this decentralized storage leader is so popular that many other blockchain-based storage system providers incorporate it in some way.
It’s worth mentioning that many blockchain-based document storage system solutions do not actually store data on a blockchain. Instead, they use non-blockchain decentralized storage for storing data, while the blockchain serves to store hashes that point to that data. Moreover, in some Web3 storage solutions, blockchains are used solely for governance or compensation purposes.
Did you know that solutions dealing with storage lands on layer four of the blockchain tech stack? To find out more, read our article exploring blockchain infrastructure companies.
Blockchain-Based Cloud Storage System – Documents and Files
Here’s a question you need to ask yourself as a dapp developer: “How should I store documents and files involved with my dapps?“. As mentioned previously, as Web3 devs, we should all aim for a decentralized future, which includes storing documents and files with Web3 storage solutions. However, certain files do not require immutability, transparency, or high levels of safety. Thus, you can focus on using blockchain-based data storage solutions for docs and files – data that must be transparent or immutable. After all, most dapps are actually some sort of Web2/Web3 hybrids. So, why not utilize the best of both worlds?
With that in mind, it’s your responsibility to use balance regarding centralized and blockchain-based storage system services. Either way, you should know what some of the top blockchain storage companies are.
Companies Offering Blockchain-Based Storage
IPFS is, without a doubt, the most popular blockchain-based file storage system. However, since it does not really use blockchain tech, we will treat it separately. As such, let’s quickly overview the following five blockchain-based data storage companies:
- Sia – The Sia project focuses on connecting those with storage to spare with those in need of it. By employing blockchain and smart contracts, Sia ensures that data is properly encrypted and that those who rent out their storage space earn Sia coins.
- Storj – Storj’s approach breaks data into smaller segments. It then uses AES-256-GCM symmetric encryption and stores it across the global network of nodes. Note that the Storj network focuses on node operators and hosting blockchain-based data storage (the supply side). On the other hand, Tardigrade covers the demand side of this Web3 storage solution.
- Arweave – Arweave is a peer-to-peer (P2P) storage protocol that mainly focuses on data permanence. The network offers extra storage capacities of network participants (Arweave clients) via the “permaweb” app, which is an immutable storage environment.
- BitTorrent File System (BTFS) – BTFS is just one of several BitTorrent products which focus on offering a scalable blockchain-based cloud storage system by utilizing the TRON blockchain. Furthermore, the system aims to reduce storage costs, avoid government censorship, and improve fault tolerance.
- Filecoin – Filecoin is an ecosystem of a cloud storage marketplace, protocol, and incentive layer. Moreover, Filecoin is a sort of blockchain-based extension of IPFS, as it uses the IPFS protocol to decentralize and secure data storage. However, it also utilizes blockchain technology to make data immutable.
Some additional blockchain-based cloud storage system companies include Züs (former 0chain), Utopia, Genaro Network, Internxt (INXT), LuminCX, MaidSafe (Safe Network), AkashNetwork (AKT), and Bullit (Bullit.app).
InterPlanetary File System Serving as Blockchain-Based File Storage
InterPlanetary File System (IPFS) is the most popular decentralized storage solution. This distributed storage protocol is possible thanks to Protocol Labs, and everyone can use this P2P hypermedia system. Furthermore, IPFS users can upload, store, and access data, websites, applications, and files without any central authority. This alternative blockchain-based document storage system uses a unique and innovative partitioning approach. The latter enables user operators to host only portions of the overall data.
IPFS is a complete paradigm shift of the location-based HTTP system, utilizing a content-addressing solution instead. This means that IPFS users search by the content itself and not by its location. The latter is possible thanks to unique content identifiers (CIDs) assigned to each partition. CIDs are essentially hashes that IPFS uses to find any specific data. In addition, IPFS also links content together by generating IPLD Merkle DAGs. Nonetheless, despite IPFS’s non-blockchain approach, this blockchain-based file storage already has a proven track record. Hence, it is the leading blockchain-based cloud storage system.
How to Add Blockchain-Based Data Storage
Unless you’ve been living under a rock, you know that Moralis is arguably the best Web3 provider. After all, its enterprise-grade Web3 API set makes creating dapps as straightforward as it gets. Plus, this provider is all about cross-chain and cross-platform interoperability. This means you can target all leading blockchains with the same lines of code. What’s more, you can use any of the leading programming languages, frameworks, and dev platforms to create killer dapps. For example, with Moralis, you integrate authentication based on blockchain without breaking a sweat.
One of many Moralis EVM API subgroups is the IPFS API. The latter lets you upload files to IPFS using the snippet of code presented at the top of today’s article. As we mentioned, we’ll show you how to do just that herein. By following along and completing the process, you’ll be able to use this blockchain-based document storage system when building your dapps. Fortunately, you only need to complete the following two steps:
- Setup Moralis
- Upload a folder/file to IPFS
However, you must first take care of some prerequisites. So, make sure to have Node v.14 or higher ready. Plus, install the NPM package manager.
Note: Moving forward, we’ll focus on using NodeJS and JavaScript; however, if you wish to use TypeScript or even Python, make sure to visit the “How to upload a folder to IPFS” documentation page.
Step 1: Setup Moralis
In case you haven’t done so yet, create your free Moralis account now. You can use the “free Moralis account” link at the outset of this article or the “Start for Free” button on Moralis’ website. With your account ready, you can obtain your Moralis Web3 API key by completing two steps, as seen in the following image:
Next, you need to install the Moralis SDK, which the following command will take care of:
npm install moralis @moralisweb3/common-evm-utils
Step 2: Upload a Folder to IPFS
Thanks to Moralis’ “uploadFolder” API endpoint, uploading any folder or file to IPFS is as straightforward as it gets. The latter comes with two required parameters: “path” and “content“. The former should contain your file’s path, while the latter is your content JSON file or “base64” code. Here’s our example of these two parameters:
path: "moralis/logo.jpg", content: "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3",
Once you have your “path” and “content” ready, use the following lines of code to populate your “index.js” file:
const Moralis = require('moralis').default; const { EvmChain } = require('@moralisweb3/common-evm-utils'); const runApp = async () => { await Moralis.start({ apiKey: "YOUR_API_KEY", // ...and any other configuration }); const abi = [ { path: "YOUR_FILE_PATH", content: "YOUR_JSON_OR_BASE64", }, ]; const response = await Moralis.EvmApi.ipfs.uploadFolder({ abi }); console.log(response.toJSON()); } runApp();
Looking at the code above, you just need to replace “YOUR_API_KEY” with the above-obtained API key. You also need to replace “YOUR_FILE_PATH” and “YOUR_JSON_OR_BASE64” with your “path” and “content“.
Once you’ve implemented your values into the above script, you can run it with the following command:
node index.js
By running the above command, you’ll upload your file/folder to this blockchain-based data storage. As a result, your terminal will provide you with the uploaded file’s path in a JSON format like so:
[ { "path": "https://ipfs.moralis.io:2053/ipfs/QmfL6fMaYJDnizFVj4wxyutDnGMePG2JL95rN2A5mcWyB1/moralis/logo.jpg" } ]
How Developers Can Add Blockchain-Based Data Storage Into Web3 Projects – Summary
Throughout the sections above, you learned all you need to know about blockchain-based storage system solutions. Initially, we answered the “what is blockchain storage?” question. Also, we looked at what kind of data a blockchain can store. Then, we also explained what blockchain-based data storage is and how it works with documents and files. Furthermore, you also learned about the top companies pushing blockchain-based cloud storage system development forward. Last but not least, you had a chance to complete our tutorial and learn how to upload files to IPFS – the leading blockchain-based document storage system.
With the knowledge obtained herein, you are ready to develop decentralized applications with actual Web3 aspects. If you need some additional guidance, make sure to use the Moralis documentation. There, you can find tutorials on how to use all of Moralis’ Web3 APIs. You can also use the power of Filecoin in Unity or other dev platforms. In that case, you want to explore the “what is web3.storage?” topic.
Don’t forget to expand your blockchain development horizons with the help of Moralis’ YouTube channel and our crypto blog. In addition, you can enroll in Moralis Academy and access pro-grade blockchain development courses where you can, for example, learn how to master DeFi.