Simple web3 integrations for your business: Peach Farmer example

Many companies are interested in blockchain technologies without really knowing how to get started. Here's an example of 4 simple integrations for your business.

Web3's front door: “Connect Wallet”

Where does a web3 experience start ? Yes, that’s it, a wallet. Every single web3 interaction comes from a wallet. The famous “Connect Wallet” button is available in many flavors :

It seems like a basic component of any web3 applications right ? However the Peach team, while experienced in web2 development, had no experience in web3 development. Interacting with a crypto wallet is daunting as it involves the user’s fund and security concerns, through signatures for example. It is also a complex issue when dealing with multiple wallet providers, networks, account switches. On top of that, The Peach team wished to have some space to not rely on us for every small adjustment they would make.

To best answer their requirements we developed a library that they can add in their project, and it handles the heavy lifting of interacting securely with a crypto wallet. It offers a comprehensive set of capabilities for working with the wallet and the blockchain, including the ability to connect to the wallet, interact with the blockchain, and sign messages. It provides a flexible and powerful solution for these tasks.

For the Peach Team, adding a “Connect Wallet” button is now as simple as calling a function.

So, how did we come up with this solution ?

The first step was communication. We sat with the dev team and talked about web3 development. We explained some basic concepts about wallets, blockchains, and a little bit of cryptography.

The second step was analyzing their environment. They opened the app’s codebase and let us wander through it, understand their architecture, and explained their work process.

We summarized what was necessary in this list of requirements: 

  1. Be compatible with their environment. They use a particular setup within their app. Our software must be able to function properly inside this environment.
  2. Simple to use. The Peach Farmer dev team are not experts in web3 development. There are a lot of concepts to learn and pitfalls to avoid when it comes to blockchain.
  3. Extensible at will. The web3 ecosystem is in constant evolution. Our software must be able to benefit from these opportunities
.

We agreed that a library was the best way to integrate web3 capabilities in the Peach Farmer App. However, wallet connection is only the beginning of anything meaningful.

Log-in with your wallet

You can trick most websites into thinking you are Vitalik.

Indeed, most websites don’t check that you really own an address. They merely show the address your wallet exposes.

I wish I could steal his style...

In order to cryptographically verify that you own an address, you must sign a message

What does that mean ? It means that you take a message (a string of character), “Helloworld” for example, transform it into a random bunch of nonsense, and pass it through your wallet which gives you a signature.

By taking the output of your wallet (the signature), and the base message, it is possible to cryptographically guarantee that your wallet signed this message. And by extension it is impossible to provide a message that would trick this verification.

So I can pretend to be Vitalik, but when a website asks me to prove that I really own Vitalik’s address, I won’t be able to correctly sign a message. Consequently I won’t be able to access protected parts of this website (a profile edit page for example). A few websites already implement this functionality: OpenSea, Twitter (yes, people with the hexagon profile picture), and Peach Farmer.

We guided the Peach Team along those security concerns. As a matter of fact those issues are extremely important to them, and to the smooth operation of the game. By playing the Peach Farmer game, you collect cards, and by the end of the season you can receive two types of NFTs: 

  • Legendary NFT: only two winners have access to this NFT each season. They are selected randomly among everyone who participated.
  • Royal NFT: the most dedicated collectors have access to this NFT by completing the season’s collection. However they must be quick as their number is limited.

They sure look nice, don’t they?

Owners of those NFTs have access to additional perks within the app: the Legendary grants you a VIP pass to the next Peach Games, and the Royal might reward you with precious $PeachCoins.

Granting access to these privileges to the wrong person would be catastrophic for Peach Farmer. Players might lose trust in the project, Peach Games might be canceled, and Peach Stars might flee from the team.

In order to avoid any wrongdoings from malicious hackers, we have provided the Peach Team with a solution to verify users’ addresses. This takes the form of an API where the Peach Team can provide a signature and an address, and the API response reports if the signature is legitimate. We have also added a function in our wallet library to generate secure messages to sign.

Great caution must be exercised when it comes to designing the message used in the signing process to verify wallet ownership. Message signing is very powerful as some contracts rely on this method for security. For example, you can sign a message allowing someone to transfer a certain amount of your funds from your wallet.

The signing process is the same. The content of the message however, is different. 

Thus, signing a message can become a scary process: it’s powerful, dangerous, and sometimes unintelligible. Moreover each platform has developed its own signing scheme: OpenSea, LooksRare and Collabland all use a different message to sign.

A better interface would not hurt

We have decided to build upon a standardized message scheme, specified in EIP-4361. This standard is being built and refined by the community. The goal is to adopt a common framework for verifying wallet ownership, making it safe and easy to use. A user being presented with this message should instantly recognize what it's used for. Besides, the standard also takes care of common attack vectors such as replay attacks, phishing, and man-in-the-middle attacks.

Accepting cryptocurrency payments

You don't say! – But have you ever tried to send money to someone on another continent ? It’s long, painful, and costly. On the other hand, cryptocurrencies provide instant, borderless, low-fees settlements for sending value.

While discussing with the Peach Team, it became clear that accepting crypto-payments was a must-have. First of all some users had their credit card blocked because their bank thought Peach Farmer was suspicious. Secondly, while Peach Farmer is 100% PEGI-13 (ESRB Teen for our US friends), we understand that some people wish to keep Peach Farmer out of their bank records. Lastly it caters to values that are dear to the web3 community : freedom of transaction, privacy, decentralization.

To take on this challenge we developed a set of smart-contract and an API to help the Peach Team accept crypto-payments. We also helped them understand the challenges of self-custody and secure their funds. Users send crypto-currency on a permissionless smart-contract which acts as an escrow waiting for the Peach Team to withdraw the funds. Thus DRENGR is never in possession of the users’ funds at any point in time. Our API handles the challenging part of validating the payment on the blockchain and sending the information back to the Peach Farmer App.

We could have gone with any cryptocurrency payment processor but this is why we chose to build our own:

  1. They take a fee on every transaction
  2. It is a proof of Peach Farmer serious commitment to web3 and its technologies
  3. It favors the spirit of decentralization and self-reliance

There are a few key points that are super important to us. Low gas fees. Adding a smart contract increases the gas fees. We were especially careful to optimize this overhead as much as possible. Flexible design. We wish we had a crystal ball to predict the future, but the web3 ecosystem is moving terribly fast and in unpredictable ways. Our design is flexible enough that it supports a wide range of use features (payment from another wallet, smart-contract accounts, currency swap). Simplicity & security. Building a complex system for the sake of complexity does not interest us. We chose a simple yet powerful design that offers a very small surface of attack.

So, how did we build this payment processor ? Time to dig into the architecture!

High level overview of the architecture

The process goes down like this:

  1. The Player sends the 1ETH to the smart contract, specifying that this payment is meant for Peach Farmer. 
  2. The Player tells Peach Farmer the payment has been made, by sending the unique identifier of the transaction (called a transaction hash).
  3. Peach Farmer contacts our API to check that the Player’s claim is true. Our API, which is connected to the blockchain, verifies that the transaction and its parameters are valid (amount, recipient…).
  4. Then DRENGR reach out to Peach Farmer and tell him whether the payment is valid or not.

This is how your crypto-payments are verified in the Peach Farmer app. Of course some details are missing for the sake of simplicity.

Building NFT collections

Now, what’s a web3 project without its very own NFT collection ?

Don’t worry we’ve got you covered! And for good measure we have even built a second one!

Fortunately NFTs do not burn the Amazon rainforest anymore

We spent several months with the Peach Team discussing, offering our experience and guidance on how to best build and integrate NFTs in Peach Farmer. Main concerns were about decentralization, innovation and security. Adding NFTs to your app is intimidating: all of a sudden, it’s connected to a worldwide ecosystem of projects, where everything is happening at the speed of light.

Our role is to help the Peach team build a secure and scalable system for managing NFTs, to guarantee that everyone can enjoy the experience.

As a reminder, there are two types of NFTs in Peach Farmer:

  • Legendary NFT: only two winners have access to this NFT each season. They are selected randomly among everyone who participated.
  • Royal NFT: the most dedicated collectors have access to this NFT by completing the season’s collection. However they must be quick as their number is limited.

The smart-contract containing the Legendary NFTs is the most important one. Indeed every Legendary NFT will be stored on this contract. We have designed it to be secure yet extensible. To do that we used a Role Based Access Control scheme that allows us to separate important functions authorization between different wallets. If a wallet is compromised, contagion is contained to associated functions, and we can replace it with another one.

We also put great care in the design of the Royal NFT smart-contract. It follows the same general principle. Considering that there will be one Royal NFT collection for each season (each season lasts around 1 month) we could emphasize a little more on security over flexibility. This will help us innovate and improve seasons after seasons.

We thought about you collectors, there will be plenty of collections to make offers on.

We believe NFTs are a great platform to build upon decentralized goods. Furthermore a whole ecosystem already exists around NFTs, built by thousands of people. This brings the security and available liquidity to a level that a single team would have a hard time to achieve.


Other articles