So, You Want to Learn to Code, for Ethereum?
A good old friend of mine reached out this evening asking how to learn to code, with the goal of making Ethereum apps. It's something I care a lot about, having taught kids to make video games using MIT's Scratch and Multimedia Fusion, then eventually reading a book on Objective-C so I could learn iOS development. I also got the pleasure of getting quite a few people into programming for Ethereum since starting MetaMask, and I've seen it change people's lives, and I think it's a really empowering skill to learn.
I eventually got frustrated by the iOS app store review process, and learned to love "the web stack": How to make apps that run in a browser. That kind of app, that anyone can post, and no one can censor, is also at the heart of Ethereum's ethos.
At its core, programming in any language tends to be pretty similar: You learn how to create "variables" to store and retrieve values.
let name = "Dan";
Then you learn about "functions", which are how you make things happen. That can look like this:
console.log(name);
// Logs: "Dan"
You can actually try both of those lines in your browser right now if you right click and select "Inspect Page", and then open the "Console" tab. You can write JavaScript right there and it will evaluate on the current page.
You can then learn how to write and call custom functions, which look like this:
function greet (name) {
console.log("Hello, " + name + "!!!");
}
greet("Drew");
Being able to define and call custom functions is at the heart of all programming. In fact, there's a whole field called lambda calculus that proves that with nothing but defining functions, you can program anything.
To program a full application for Ethereum today, you'll end up needing to learn at least two languages:
- Solidity (for the smart contracts)
- Another language (for the interface)
If you want to program for the web (which I recommend), then the language of choice for the second one is JavaScript. Along with JavaScript for the page's behavior, you'll need to know at least basic HTML and CSS.
HTML is the language of content on a page. It looks like this:
<!doctype html>
<html>
<header>
<title>My Site</title>
</header>
<body>
<h1>Welcome To My Site!</h1>
<img src="./logo.jpg" />
<p>Under construction, stay tuned!</p>
</body>
</html>
You'll notice that there are "tags". Some tags have both an <opening>
and a </closing>
tag to indicate where they control, like h1
for a big header, or p
for a paragraph. Other tags work fine with no closer, like an img
tag.
Tags can have optional attributes, like the src
value on the img
tag, which tell it what to render. I just described most of the HTML syntax you'll ever need to know, and from there most of applied HTML is about knowing which tag to use. You can try out some basic HTML on a variety of web sites that let you edit and see the results in real time, like CodePen.
On that page you'll see that I also made a very simple CSS file where I make the h1
tag the color yellow.
h1 {
color: yellow;
}
CSS always looks like that: You have a block that starts with a "selector" (it can be a type of tag, or something more specific) and then a series of attributes and values to set them to, separated by a colon. Multiple values are separated by a semicolon.
Lastly, you can have a JavaScript file imported into an HTML file that can interact with the page: It can respond to clicks, and it can edit the entire page in any way.
The MDN site is a great way to interactively tour all three of the web languages: HTML, CSS, and JavaScript, and you can even use it to learn them all (it has interactive lessons).
Another site with interactive lessons on those today is FreeCodeCamp, and it helps keep track of your progress, so that might be more motivating.
I've also had good success with students going through the Khan Academy computer science program.
My advice is to try to make a few web sites, and maybe even some simple web apps to get the skills warmed up. I like making little web apps all the time. I recently made one for entraining my brain with beat waves. One of my first apps was one for estimating the probabilities of different scenarios in the board game "The Resistance". I even made a little script for estimating how far out to water a tree. You can make a web app for anything.
Once you've learned the basics of HTML, CSS, and JS, you'll inevitably be encouraged to learn a "framework" like React, or Next.js. These are basically sets of tools (mostly JS) that make it easier to update the page in response to user interaction. I think it's really great to understand the basics first, because then you will have an easier time understanding what's going on with all the magic in those frameworks, but they speed up people who know how to use them well.
I recommend learning Solidity after you already know and are comfortable with a language for a couple reasons:
- Solidity's feedback loop is a little slow: It can take longer to see the results of each try.
- Solidity is a bit more complicated than a scripting language like JavaScript. It has types (every variable can only store a certain kind of data) and a few other constraints that make it harder to learn as a first language.
Once you're ready to learn Solidity, my personal favorite resource is BuidlGuidl. I've also kept note of a few threads full of people suggesting other resources:
Solidity devs! Is there such thing as a good "100 days in @solidity_lang"? My default recommendations are still crypto zombies, read popular contracts, read the Solidity docs and do Speed Run Ethereum... Pls drop your fave up-to-date resources for getting started below! 📚🧙♂️🧙♀️
— franzi (@_franzihei) January 23, 2023
What are your recommendations when someone asks how to get started in smart contract development?
— Santiago Palladino (@smpalladino) March 20, 2021
My usual reply is:
1- Start with https://t.co/o1i8qOGZkh
2- A language @solidity_lang
3- A library @OpenZeppelin contracts
4- A client @ethersproject
5- A toolchain @HardhatHQ
However you learn it, you'll end up using some command line, so you'll need to know at least some basic shell commands, and probably even git. Git is a tool for saving your progress in a way that you can always roll back mistakes, and is also a great tool for collaborating, so multiple people can propose changes to the same code at once. I read the git book early in my programming career, and I think it gave me a big advantage. A lot of people who only learn the bare minimum of git end up making life harder for themselves when they want to do simple things. Understanding how it works (it's not that complicated) helps avoid confusion later. Basically all code collaboration today is done using git over a hosted website like GitHub or GitLab.
Between command line, git, solidity, and the web stack, you'll have most of what you need to cobble together a basic Ethereum application. As you go, you might learn there's a feature you want that requires learning how to interface with a new service. Every time you interface with a new thing, you end up wanting to look up its "API docs". API stands for "Application Programming Interface", and once you learn how to look up an API and interact with it from your own code, you're basically free to interconnect all the computer services you want however you want.
Eventually, you may learn you want to run a server process yourself, maybe just a database of signed up users or something. For that, I recommend node.js. It lets you write JavaScript on a server so it can do extra stuff even when your users' web browsers aren't open.
If you have a feeling you'll want to write backend services too, you might want to start with a more full stack web class like they offer on Udacity. This will involve learning another language, Python for the server. Python is really simple, and is used a lot in AI today. It will be a small detour, but I took a few of their classes back in the day, especially their Intro to Web Development, and it taught me some basics about how servers implement authentication and security that I think is really useful and holds back a lot of new developers who don't bother learning it.
You'll eventually learn that AI is really great for helping generate or edit and fix blocks of code you're working on. Feel free to try it out as you go. You'll probably find it's great for some things, but try to understand how everything is working before learning on those tools too hard, or you'll eventually hit a bug that will stop you in your tracks. I'll save most of those recommendations for the future.
Anyways, I hope this is enough to start exploring, and getting a sense of what there is to learn. I know that was a lot, and I'm not going to lie, it is a lot. It took me probably 3-4 years of hacking around teaching myself to code before I got my first programming job, but if you want to just make your own thing, you can do it a lot sooner. Having something you want to make is a really powerful thing, and I recommend holding onto that and just keep making things you'd like to.
Good luck, and enjoy!