August 23, 2022

How to Use Filecoin in Unity for Storage

Table of Contents

Decentralized storage solutions are one of several popular blockchain use cases. After all, we appreciate the practicality of using cloud storage without relying on any particular centralized entity. This is where Filecoin has been pushing the boundaries by adding incentivized and persistent storage to IPFS. Moreover, since Web3 gaming offers countless opportunities, we decided to explore how to use Filecoin in Unity. Our idea was to save and load images utilizing decentralized storage. This use case could then be applied to Web3 games, NFTs, and other types of dapps. Also, we decided to use the power of some awesome Web2 and Web3 tools to turn our idea into an excellent dapp. 

We used Moralis’ authentication solution to cover Web3 login, Filecoin for storage, and Unity as a game engine. Of course, we leave it up to you to take our concept and use Filecoin in Unity in your unique way. Moving forward, we will take a closer look at our Filecoin utilization example application. The latter is a neat way to use Filecoin in Unity by storing and retrieving PNG files. As we present this example project, you will learn the basics of Filecoin. Hence, you’ll also find it easier to decide whether or not this may be the right storage solution for you. Furthermore, you will also get acquainted with Moralis – the ultimate Web3 backend solution. While we will focus on using the Moralis Web3 Auth API herein, Moralis has much more to offer.

Aside from Web3 authentication, Moralis’ Web3 syncs and the Moralis Web3 API help you effortlessly create all sorts of killer dapps (decentralized applications). So, create your free Moralis account and make your Web3 development as straightforward as possible.

Filecoin Network 101

Understanding the basics of Filecoin can help you properly use Filecoin in Unity. So, let’s start by pointing out that Filecoin is an open-source solution. It is a cloud storage marketplace, protocol, and incentive layer. The Filecoin network is built on IPFS and offers decentralized and secure data storage and retrieval. According to Filecoin.io, this decentralized storage network strives to offer a more efficient and secure web free from corporate control.

Moreover, the Filecoin network achieves staggering economies of scale. It does so by allowing anyone to participate as a storage provider, thus, ensuring hypercompetitive prices. As such, the Filecoin network is made up of a large number of diverse storage providers and developers. This diversity creates a robust and reliable service. Essentially, this open-source storage is built and owned by everyone.  

Filecoin offers provable security and authenticity. Thanks to content addressing and cryptographic storage proofs, the network verifies that the data is being stored correctly and securely over time. Furthermore, you can customize this storage solution to match your needs by tuning redundancy, retrieval speed, and cost strategies. Nonetheless, the Filecoin network is a rapidly growing ecosystem of tools, libraries, providers, and integrations. For more details, explore the official Filecoin website.  

Meet Moralis – Your Gateway to Effortless Web3 Development

Since Moralis’ Unity SDK enables us to use this popular game engine for Web3 development and, therefore, use Filecoin in Unity, you ought to learn more about this excellent tool. However, unless you’ve been living under a rock, odds are you are already acquainted with Moralis. If nothing else, you learned in the introduction that Moralis is the ultimate Web3 backend platform. It is all about empowering legacy devs to easily join the Web3 revolution. 

Since Moralis is cross-platform interoperable, you can use its power with different platforms and programming languages. Furthermore, Moralis was also designed with cross-chain interoperability in mind from its inception. Accordingly, the platform supports all leading programmable chains, including Ethereum, Solana, BNB Chain, Polygon, Avalanche, Cronos, Fantom, and others. Hence, you get to use the same lines of code to expand your reach. Also, the fact that Moralis continues to constantly add full support for new chains also future-proofs your work.

Ultimately, Moralis enables you to add Web3 authentication, Web3 syncs, and countless other Web3 features to your applications with single lines of code. Additionally, you get to copy these lines of code from a neatly structured Moralis documentation. As such, you can save a ton of time and resources on backend development. Moreover, this enables you to devote your maximum attention to creating the best possible UI and UX. So, in case you haven’t done so yet, make sure to create your free Moralis account now and start deploying awesome Web3 apps.   

How to Use Filecoin in Unity for Storage – Example Project

We approached this project by asking ourselves, “what options do we have to combine Filecoin with Unity?”. Further, we wanted to be able to store and fetch assets. Also, we decided to focus on images (PNGs) in particular and use them in all sorts of ways. This way of thinking led us to Web3.Storage, which offers storage and an HTTP API. Hence, we knew that we could use that API to call everything we needed from inside Unity. So, to follow our lead moving forward, you’ll also need to complete the initial setup for that neat tool. Moreover, you will also want to clone our code or download our project ZIP file that awaits you on GitHub:


However, before you open our example project, let’s take a closer look at our Unity dapp.

Use Filecoin in Unity for Storage Utilizing Our Dapp – Demo

Note: You’ll be able to play around with our dapp after opening our project in Unity and completing the initial setup. The below-presented screenshots revolve around the “Example_Filecoin_Storage_01” scene.

The above screenshot indicates our example dapp’s interface in the middle. As you can see, we titled our dapp “Filecoin” and broke it down into the “Main” and “Details” sections. Furthermore, the dapp displays our address in the top-right corner since we’re already authenticated. Moreover, below the “Details” section, you can also see an example PNG image that we are uploading to Filecoin. Nonetheless, if you decide to work with our dapp to use Filecoin in Unity, you will also get to explore the three buttons at the bottom. On the far left side, there’s the “Open Image (Browser)” button, which opens the uploaded image in a browser. Then, we have the “Save Image” button, which saves the selected image to Filecoin. Last but not least, there’s also the “Clear Image” button, which removes the image from your dapp. 

Moreover, if you look at the “Main” section, you can see that our dapp first uploaded the file, then obtained its status, and finally downloaded a stored file. Our dapp does the entire cycle just to demonstrate both the storing and retrieving of PNG files.  

Furthermore, let’s now click on the “Clear Image” button:

As mentioned above, this button clears the image (its sprite) from the UI:

If we were to repeat the process of saving the image, we’d need to use the “Save Image” button. This would also reactivate the “Open Image” button. In addition, if you wanted to store a different image, you’d need to use the “inspector” tab and change the file next to “Sprite To Save”:

Use Filecoin in Unity for Web3 Games 

Now that you know what to expect from our example dapp, it’s time to open it and complete the initial setup. This is where we recommend you start with the “ReadMe” asset inside the “Documentation” folder. It will take you through all the steps you need to complete to use Filecoin in Unity with our dapp. Also, don’t forget to create your Web3.Storage API token.

Web3.Storage – Bridging Filecoin and Unity

If you want to use Web3.Storage, visit this tool’s official website, sign up, and create your API token:

Moreover, inside your account, you’ll be able to see all the uploading activity made inside Unity. This is quite useful while in the debugging phase of your project:

Note: You may also upload the files using Web3.Storage’s dashboard directly and then retrieve those files inside Unity.

Once you get to step five of the “ReadMe” asset, you will get to give our dapp a test run. Once you get comfortable with using it, it’s up to you to think of some cool ways to use this tool for your Web3 gaming feats. If you have some good ideas, we strongly encourage you to register for the Moralis x Filecoin 1, 2, Web3 Hackathon and get a chance to collect your share of the $190,000 and counting prize pool!   

Code Walkthrough

In this section, we will take a closer look at the script powering our “Filecoin” dapp. For details, we will point you to the specific part of the video tutorial below. In this video, you will hear it directly from the creator of the “Filecoin” Unity dapp, our in-house Unity expert. As such, you will have a chance to get to know our example dapp on a different level. However, make sure you first take some time to explore the project layout. If nothing, this will help you get around a lot more smoothly:

The main script for our above-presented example dapp is called “Example_Filecoin_Storage_01”, written in C#. Moreover, starting at 6:40 of the video below, our Unity expert covers some key aspects of this script. One of the key methods is “Filecoin_UploadAndGetFile“, which does exactly what its name says:

Furthermore, for your convenience, the script includes many useful comments, including the setup instructions for Web3.Storage:

However, since we’ve covered that above, you know that you only need to paste in your API token. In addition, looking at the “Example_Filecoin_Storage_01” script, you will also see that the “UploadFile” function accepts the bytes that our dev created by converting the example image:

Then, at 7:29, you get to take a closer look at the “GetStatus” method, which can be useful in certain instances. Next, you’ll get to look at the lines of code that fetch the PNG files. The “GetFile” API call provides us with the bytes for our file. As such, we need to render the bytes to create a sprite. Finally, you’ll also have a chance to look at the lines of code that provide the data in a format suitable for our UI (8:10).

Filecoin, Unity, Web3.Storage, and Moralis – Our Video Tutorial

Finally, here’s the video tutorial that we’ve been referencing above. Aside from a more detailed code walkthrough, this is where you can learn all you need to know about Filecoin, Unity, Moralis, and Web3.Storage to get your hands dirty. Starting at 8:47, you can learn more details about the hackathon mentioned earlier, including the prize pool breakdown. 

How to Use Filecoin in Unity for Storage – Summary

We covered quite a distance in this article. First, our discussion ensured that you know what Filecoin is. Hence, you learned the basics about this decentralized storage solution. Next, we introduced you to Moralis – your ticket to easy Web3 development. Accordingly, you discovered that this ultimate Web3 development platform offers you a simple way to use your favorite Web2 development platforms to create dapps. Moving forward, we put our focus on how to use Filecoin in Unity. This is where you also learned about Web3.Storage, which provides you with an API to communicate with Filecoin from Unity. Moreover, you also had a chance to look at our example “Filecoin” dapp and even create your own instance of it. Lastly, our in-house expert walked you through the code behind our example dapp.

In addition, you also learned about the Moralis x Filecoin 1, 2, Web3 Hackathon, which offers quite an impressive prize pool. So, if you know your way around C#, use Filecoin in Unity and create awesome Web3 games. However, if you first need to polish your Web3 skills a bit, taking on some interesting example projects should be your primary focus. Fortunately, you can find many tutorials on Moralis’ YouTube channel and the Moralis blog. Of course, learning how to convert Unity into a powerful Web3 development tool with Moralis’ Unity SDK is just a small portion of what’s possible. Essentially, these two outlets can show you how to create all sorts of dapps quickly and easily. 

Nonetheless, another path, a more professional one, which goes beyond the “use Filecoin in Unity” topic, is to enroll in Moralis Academy. Moralis Academy is the number one Web3 education platform online. There, you can become blockchain certified fast and go full-time crypto in no time!  

Moralis Money
Stay ahead of the markets with real-time, on-chain data insights. Inform your trades with true market alpha!
Moralis Money
Related Articles
July 9, 2024

DeBank API Alternative – Best Free DeFi API to Track DeFi Positions 

August 12, 2022

Moralis Projects – Web3 Magic Treasure Chest

January 1, 2024

Full Web3 Wallets List – Exploring the Best Web3 Wallets

January 19, 2023

Web3 Get Block Feature – Use a Web3 Get Block Timestamp Function

November 20, 2022

NFT Collection Data – How to Get NFT Collection Data

December 7, 2023

Which is the Best Crypto Exchange API for Web3 Developers?

October 25, 2022

What is Sui Blockchain? – The Ultimate Guide

August 31, 2022

Fastest Way to Build a Web3 App

June 10, 2024

Polygon zkEVM RPC Nodes – How to Set Up a Polygon zkEVM Node for Free 

🔥 LIMITED-TIME OFFER - Get early access to an Enhanced Token Page & boost your token project’s exposure! GET EARLY ACCESS 🔥