A Decentralized Frontend: gTrade Migrates to IPFS

Gains Network
6 min readSep 14, 2022

Hi, gTraders!

We had a pretty eventful August. Some new features like the implementation of $GNS Single-Sided Staking and the Referral Program were in the pipeline for a while. Other changes, like the one we will talk about in this article, came completely by surprise! The ability to solve problems as they arise without sacrificing the integrity of our feature schedule is a testament to the gTrade team’s ability to be agile, build well, and ship fast.

The vision behind gTrade is to become the fairest, user-friendly decentralized leverage trading platform. There are different aspects to decentralization. Here are three that gTrade is focused on:

  1. Revenue — $GNS holders own gTrade through receiving a share of the trading fees
  2. Governance — gTrade will implement a governance function
  3. Website — gTrade has transitioned its web-hosting to IPFS (the topic of today’s article)

A platform is not decentralized if it has a single point of failure. Unfortunately, even crypto protocols that use distributed ledger technology rely on centralized systems for their web hosting. This means that although the data stored on blockchains are antifragile and will continue running, the user will not be able to access this data in a user-friendly manner if a project’s website is down due to:

  1. Censorship
  2. Server issues
  3. DDOS Attacks

Unfortunately, we fell victim to the last factor a couple of weeks ago when gTrade was the target of a DDOS Attack. This resulted in a temporary ban for the gTrade web domain in Netlify, the previous hosting solution we were using, which motivated us to explore other hosting solutions — the most decentralized of which is IPFS.

DDOS Attacks

A major problem with centralized hosting is that a website will go down if it’s suffering from a server issue. This is the weakness that DDOS Attacks (Distributed Denial of Service) capitalize on. Malicious computers flood the target server with a high enough volume of fraudulent requests that cause normal users to no longer be able to access a website hosted on the target server. The malicious computers “deny service” to normal users this way.

Servers are the single point of failure for most websites (and for most of the internet). Hosting a website on a single centralized server is at odds with the ethos of decentralization that gTrade is pursuing.

gTrade nearly falling victim to one such DDOS attack recently was the straw that broke the camel’s back, and propelled the migration to IFPS from low priority to highest priority.

As an added drawback, traditional websites also suffer from arbitrary censorship when governments strongarm the companies that own the server farms into regulating the content of these websites.

It’s for all the reasons above that centralized website hosting is fundamentally incompatible with the ethos of decentralization.

IPFS

IPFS stands for Interplanetary File Service. It’s a distributed file system protocol that stores data on a P2P network similar to how BitTorrent works. Unlike the traditional web that stores a file inside a single location-based server, IPFS stores files in multiple places in its network of IPFS Nodes.

Anybody can run an IPFS node to store data from other people on their computers. Data is not retrieved by pointing your computer to a specific web address (location-based addressing). Instead, IFPS uses “Content” Based Addressing, which is the equivalent of asking all the nodes on the network where a specific file is located.

The more IPFS nodes store and pin your data, the less vulnerable your data is to a single point of failure. The same set of data being stored in multiple nodes makes the data antifragile.

However, IPFS storage is slower to access than regular content on the web, because it has to search through the IPFS network for the node which hosts your content, especially when you want to access IPFS-hosted content through an IPFS gateway. IPFS gateways are public IPFS nodes that everyone can use to access content on the IPFS network.

It is slower, but its decentralized nature makes it the superior choice for crypto projects like AAVE — and now Gains Network.

gTrade’s Decentralized & Efficient Solution

At the end of the day, ease of use is a top priority for the gTrade team because gTrade is a user-centric platform. If the gTrade website was purely accessed through a public IPFS gateway and always took minutes to load, that would be against the user-friendly priority and extremely unfavorable for swing traders.

The win-win solution we’ve found not only lets us leverage the decentralization and availability of the IPFS network, but also the speed of a CDN (Content Delivery Network) and the ease of use that the DNS (Domain Name System) provides.

This means the gTrade website can still be accessed through the https://gains.trade domain name (fast, 99% reliable, hosted on IPFS), but it can also be accessed through any IPFS gateway (slow, 100% reliable, hosted on IPFS) via typing a special hash (the content ID of the website) that is updated with every new deployment.

Accessing through an IPFS gateway takes 2–3 minutes to load, but it will always be there, and once it’s loaded it stays in the cache and can be loaded again instantly. Example: ipfs.io/ipfs/<content-id>

Even if the gTrade DNS / CDN provider would go down, the website could still be accessed through any IPFS gateway without centralized dependence. In other words, you will always have a way to access (and trade on) gTrade.

In this case, the DNS / CDN provider for the website front end used for the https://gains.trade domain is for user convenience. It’s optimized for speed and scaling — like the cherry on top of the cake — while all the data of gTrade has now been fully migrated to IPFS and is stored in a safe, decentralized manner.

A telegram bot that will share the IPFS content IDs of each new deployment of the gTrade website will be created very soon. It is probable that old deployments won’t stay hosted on the IPFS network, because it would require IPFS nodes to store all previous versions, which would take a lot of disk space. If someone wants to host and pin all versions on his IPFS node, it is possible, but quite unlikely. Therefore, it will be important for users to keep track of the latest IPFS content identifier.

To conclude, the accessibility of the gTrade website does not depend on the team anymore, as it can be pinned by anyone running an IPFS node and it can always be accessed through any IPFS gateway.

Problem Solving

It’s important to note that IPFS wasn’t made specifically for websites — it is only a file storage network. The gTrade team had to transition the website from React to Next.js to make it IPFS-compatible while maintaining normal page URLs (/decentralized-trading vs /#/decentralized-trading/) which is important to have good SEO and a good UX.

Now, each page of the website is pre-rendered into a .html file (eg. referrals.html for the referrals dashboard page), which is not only much better than before for our SEO, but also loads much faster (approximately 2x reduced loading times compared to before).

This was all completed in the span of one week. The gTrade team can roll with the punches and has proven its track record in building and delivering regardless of black swan events.

Whether it be during good times or trying times, the gTrade platform will progress in only one direction: towards continuous and unstoppable improvement.

Thanks for reading!

--

--