Creating My First Decentralized Application
Welcome to the Zenith Chain newsletter, a place for people who are interested in blockchain engineering, smart contract development, and the web 3.0.
Today’s newsletter will give you a primer on my journey to creating my first Ethereum application.
I write technical articles just like this one every Monday for subscribers of the Zenith Chain newsletter.
And if you haven’t subscribed yet, feel free to hit the subscribe button below. All of my articles will be free for the foreseeable future, so you have nothing to lose!
If you are interested in Ethereum and smart contract development but you aren't exactly an ace software developer, or maybe you have no coding knowledge at all, then you are in the right place. In this article, I briefly talk about my background and how I was able to go from no coding experience to creating my first decentralized application within a year.
I've been in the cyber and tech world for about eight years, but I've had little to no exposure to the software development side of things. I left my last cybersecurity job back in March, days before the world started freaking out about COVID, leaving me unemployed for months due to the lockdowns.
What better time, I thought, to finally pick up a coding language or two?
Picking a coding language, or languages I should say, was easy. I wanted to get into blockchain engineering and smart contract development. Why? Because for once in my life, I wanted to get ahead of the herd. I wanted to get ahead of something that is not only fascinating, but revolutionary.
Not only that but smart contracts, along with decentralized oracles and blockchains, provide a layer of trust in agreements that is orders of magnitude higher than we have today.
When you combine the fact that agreements in some form or another power all global trade and commerce with the fact that trust is the most powerful economic force in the world, it seemed like a no-brainer for where I wanted to take my career next. Smart contracts will dominate, and there will be a serious need for blockchain engineers and developers.
If you aren't entirely familiar with what a smart contract is, Investopedia's definition is:
A smart contract is a self-executing contract with the terms of the agreement between buyer and seller being directly written into lines of code.
What You Need To Know
When creating an end-to-end application on Ethereum, you have to not only have knowledge of how to create a smart contract, but also how to create a front end, or a user-facing website. Together, these two pieces essentially combine to form a decentralized application.
I'll have to warn you that although React is super cool, it's a bit of a beast to learn. Don't skimp on the fundamentals before moving on to frameworks or libraries.
Smart Contract Code
Without further ado, let's get into the smart contract code for my Ethereum application. Just as a warning, though - this is a high-level walk-through, so don't expect a detailed explanation of every little aspect of the code or the application.
Don't get too caught up in the details or what every little part does if you aren't familiar with Solidity. Just know that the code essentially takes in a string, or any combination of letters and numbers, stores it in an array, and writes it to the blockchain when the user hits the submit button on the website.
Along with the string, the application records whatever blockchain address you were using at the time. Scroll back up to see what the application looks like after recording a few messages if you need to.
The code above has two functions. The first function setMessage takes in a variable that allows you to change the message and then push the message into the savedMessages array. The second function getMessage simply just returns the strings that you saved in the array when it is called. And that's about as complex as it gets.
I originally wrote this smart contract on a free Solidity coding platform called Remix. Remix allows anyone to write smart contracts on their website, deploy them to a test blockchain, and interact with the functions to test them out. It's an awesome tool and I highly recommend you check it out.
In the React website that you can see at the beginning of this article, I used a CSS framework called Bootstrap for styling. It's yet another thing to learn but makes styling your website considerably easier. In the Navbar in the upper-right hand corner of the app, you can also see the blockchain address that I was connected to at the time.
It took a good amount of React code to put together my application, but I found it pretty cool to not only see how smart contracts "plug in" to front-end websites, but to actually make it happen myself. The React code essentially manages the user interactions with the website and calls certain functions within the smart contract, which in this app's case, recorded the strings to the blockchain and displayed them back to us on the website.
I'm not going to cover the front-end code or go into detail on everything you need to know for that, but if you wanted to at least look at the code, you can check out my Github repo.
Putting It All Together
To name a few - private blockchains like Ganache for testing out your application locally, testnets, mainnets, knowledge of the underlying Ethereum blockchain architecture and how smart contracts work behind the scenes, development frameworks such as Truffle or Hardhat, and blockchain wallets and gateways such as Metamask.
As you can see, there is basically a mountain of information that you need to know that goes into creating even the most basic Ethereum application. But don't let this scare you off! If it was easy, everyone would be doing it. And hopefully, if you are anything like me, this stuff excites you and you love to learn.
I estimated that over the course of one year, I probably put in on average 2-4 hours a day learning how to code as well as learning the surrounding blockchain development technologies. That equals anywhere from 600-1,200 hours to build a basic Ethereum application!
It hasn't exactly been smooth sailing or a nice straight linear path to get to this point, but it's important to realize that it's a marathon, not a sprint. You don't need to be a genius to learn any of this either. Consistency, passion, and a solid work ethic are all that it takes.
Thanks for reading this edition of the Zenith Chain newsletter. If you enjoyed this article and want to learn more, I’ll be releasing similar articles like this every Monday. Completely free. If you would like to stay tuned for more content like this, feel free to sign up below!