DEV Community

CoinMonks
CoinMonks

Posted on • Originally published at Medium on

How did I write my first Dapp in Reach?

How did I write my first dApp in Reach?

I have been interested in blockchain for about three months now. At first, it was like a Pandora’s box; dApps, hashes, merkle trees, DAOs and many other words were thrown around. It frustrated me as a mobile app developer. The progress I made was very unsatisfactory compared to the time I invested.

Then I learned about Reach, a blockchain development platform claiming to be the “fastest, safest, and easiest way to build on blockchain”. Despite my initial skepticism, I decided to give it a try. The moment I finished the tutorial (having written my first blockchain application in two days) I understood: this was it. I could finally turn my ideas into functioning dApps.

Reach announced a “Bounty Hack” event in February to promote development of apps on the Algorand network, strengthen its infrastructure, and introduce more programmers to Reach.

The following app I’m about to talk about is my submission to the Reach Bounty Hack, a hackathon event in which the primary goal is to encourage new developers to write their own Reach applications.

When I first heard about it, I had just finished the tutorial and had no idea how to build an entire application from scratch myself. Even though I wasn’t confident that I could finish it to the end, I decided to give it a try.

I hunkered down, diving into the documentation and tutorials; all the while, harassing Reach’s development team with an endless barrage of questions (huge thanks to Jay, Chris, and Dan for being so patient!). Mentors began to emerge within the community. Before long, I became the one offering encouragement and support to the steady flow of newcomers writing programs in Reach. Five weeks later, my masterpiece was complete: a decentralized version of a first-gen Pokemon game called “Pokéchain’’ in which players lock in their moves with a transaction. It ran on a Game Boy Advanced emulator_…_and Algorand.

A screenshot from my game

How it Works

Pokéchain is an Algorand-based blockchain game where players commit their moves to the blockchain. Moves are played after being confirmed by consensus. Players pay a price for their move which is collected into a pool where it can either be transferred to the creator of that session or distributed among players following various rules.

“Why Algorand”, you might ask.

If you are familiar with Ethereum development, the answer is obvious: Algorand is much faster and cheaper on gas fees compared to what Ethereum offers. Gas and transaction fees for a simple game on Ethereum cost roughly 90 dollars. On Algorand, these fees are reduced to below two dollars.

Big Surprises

Thinking back on the development process, I was surprised to realize that the easiest part of development was the blockchain part. Thanks to Reach’s abstraction of lower-level Solidity and TEAL code, a game which would normally take hundreds of lines to write in a complex developer environment took only 80 lines of code to write in Reach.

As programming languages go, Reach is relatively straightforward. It’s syntactically and semantically similar to JavaScript; apps are specified in JavaScript syntax. In many scenarios, the design logic Reach applies to contract participants made the coding process as simple as writing a script for the stage.

I had some trouble building out the frontend because it was my first time writing a project for React & Node.js. I really struggled with state management because the nature of Dapp’s was hard to combine with a React app. That’s where my teammate, Namiq (sn#3348) came through with the clutch assist. He helped me style the pages and manage the states of the app.

Although we hit a few snags near the end, I’m much more comfortable writing React code and managing states in a dAapp now. Reach already supports any frontend library. From what I heard from the development team, Reach is going to support all frontend languages soon (with the upcoming RPC server feature). As a Flutter developer, I’m very excited to see the direction Reach is going.

There is also code written in Python to play the Pokemon game when inputs are given. Those steps are just basic PyAutoGUI functionality combined with Requests library. I based the bot from the classic ‘Twitch Plays Pokemon” project which was also the starting point of “Algorand Plays Pokemon” (the project I was assigned in the Bounty Hack).

I was looking at a working version of my game after just two weeks of development. Moments like this remind me how amazing it feels to be a developer. Seeing my idea come to life in such a short span of time, I can say with certainty that Reach makes blockchain development as easy as possible. Thanks to the simplicity of the code-base, it’s fairly easy to improve on what I’ve built so far.

The latest version of the game where you can input multiple moves at once

I am truly thankful to Reach for providing me with a platform for turning my ideas into well-functioning blockchain apps in a fast and easy way. I also want to thank the other Bounty Hack participants for voting for our dApp. We weren’t really expecting to win among the great projects other friends from the community have made. I can’t express enough how happy I am to have been a part of this.

If you’re not sure about writing your blockchain applications in Reach, my only suggestion is to at least give it a try. I’m sure you’ll find more than I can explain in this short article.

If you want to see my game in action you can check my video explaining it.

You can also see the source code of the project here in Github.

Thanks for reading and have a nice day!


Top comments (0)