Darknet Games : Building a Wagering System for PvP ("Player versus Player") Games on EVM-Compatible Blockchains

Services: Fullstack blockchain development / Timeline: 1 month / Blockchain: Ethereum

Overview

Darknet Games is a marketplace for games and a social network where people can play against each other in crypto-wagered matches. Apollo Launchpad built their wagering system for EVM-compatible blockchains so that any partnered game developers can easily integrate and list their games on the platform.

The Challenge

Darknet Games approached us because they needed experts who could build their system with both robust security and high performance at its core. Transfers of funds on blockchains are virtually irreversible, so following the best security practices on all fronts were of the upmost importance. This had to be accomplished without compromising speed and usability, since good user experience (UX) and user interface (UI) were crucial for an online gaming platform like Darknet Games. Furthermore, the system had to be designed in a way such that it could easily be integrated with partnered games for smooth onboarding. We also had to take into account the inherently slower and more expensive transaction speeds of popular EVM-compatible blockchains such as Ethereum, and to optimize for usability and costs accordingly.

How did we build the wagering system so that it was not only highly secure, but also fast enough for users and easy enough for game developers to integrate?

Our Process

1

Build the financial logic

We knew that we had to build almost all of the logic related to user funds and wagers at the smart contract level. This is because once a smart contract is deployed, it is immutable and tamper-resistant, making it inherently more secure than traditional server-side infrastructure. The decentralized, verifiable nature of smart contracts also makes users more comfortable interacting with and trusting the platform. Our next step was to determine the optimal data structure native to the Solidity programming language to efficiently store and frequently update user balances data. This would be particularly important for popular EVM-compatible blockchains with relatively expensive storage and transaction costs, such as Ethereum. We ultimately decided to leverage Mappings for three key reasons:
  • Read and Write Efficiency - Mappings provide constant-time lookups, which means accessing or updating a specific key-value pair in a mapping has a fixed gas cost, regardless of the size of the mapping. In contrast, arrays require iterating through the elements to find a specific value, resulting in linear gas costs proportional to the array size.
  • Lower Gas Cost - Mappings can be more cost-effective when it comes to modifying or updating values. If you need to update a value in an array, the entire array might need to be rewritten, resulting in higher gas costs. With mappings, only the specific key-value pair is modified, leading to lower gas costs.
  • Storage Size - Mappings do not occupy space for all possible keys, unlike arrays. They only store values for keys that have been explicitly assigned. This can result in significant storage savings when dealing with sparse data or large mappings with a limited number of assigned keys.
2

Then, Choose the Right Client-side Technology

We chose ReactJS for our frontend framework for a several reasons. One was that its virtual diffing algorithm and efficient rendering made it high-performant, which was important for good UX and UI. Another was that there was a large number of web3 libraries supported on it. ReactJS's component-based architecture, as well as its popularity among developers, also made the wagering system very easy to be integrated by partnered game developers, facilitating onboarding.
3

Optimize Server-Side Security

The users themselves would interact with the blockchain strictly through client-facing interfaces like MetaMask, but the wagering system still needed to be able to sign transactions from the server-side when transfering the wagered amounts from escrow. This meant that we needed to implement the best security practices to securely store the private key on the server. Although we cannot get into the specifics for obvious reasons here, we took steps such as strategically placing our .env file, encrypting it using an AES Encryption algorithm and implementing logging and monitoring mechanisms of the private key. This maximized the security of the private key.

The Outcome

Within a month, we completed the wagering system ahead of schedule so that it was highly secure, high-performant, affordable and easy to be integrated.

Darknet Games released their demo platform accompanied by a membership NFT collection of 3818 NFTs at 2 SOL ($ USD in today's price).

"The team has an incredible attention to detail when it comes to making secure and scalable smart contracts. Their knowledge, punctuation, and ability to solve problems makes them a joy to work with."
- Anthony Gonzalez, Founder of Darknet Games