As a programmer, I like creating efficient and scalable systems. In my personal life, I noticed a bottleneck. Everybody was asking me how to learn Solidity, engineers and non-technical folks alike. So I compiled (see what I did there?) a half dozen or so resources I found useful and emailed them to some people. But every time someone asks me, I have to scroll through my “Sent” inbox to find it, and then forward it. So, masquerading laziness for efficiency, as well as to provide a more robust overview, I decided to write this blog post. Copying and pasting one link is easier 🙂
If you’re reading this you probably know a thing or two about blockchain and smart contracts, but if you don’t here is a quick summary:
Solidity is a programming language for smart contracts on Ethereum and EVM blockchains. Smart contracts are code that exists on the blockchain that people can use trustlessly: everything from DeFi, bridges, NFTs, NFT marketplaces, games, etc. are all powered by smart contracts.
Ethereum has the Ethereum Virtual Machine, or EVM, which acts as its computing layer. Given the strong developer community around it many blockchains have decided to become EVM-compatible, meaning that the smart contract functionality is exactly the same, among other things (JSON-RPC wallets, gas fee calculation, etc.).
In fact, the same exact code can be run on Ethereum as can on any EVM blockchain, making it easy to scale a product across multiple chains. The most popular EVM chains are Avalanche, Polygon, and Fantom, but there are many more.
Approaching Solidity as a New Developer
- CryptoZombies – everyone and their mom has heard of this one, but it is a tried and true resource to learn Solidity in a fun, gamified way
- Solidity by Example – if you’re the type of person who enjoys reading the textbook for class, then here is a great starting point as well. This site has bite-sized chunks of core Solidity concepts in application
- EatTheBlocks – if you learn best by videos, they make great YouTube tutorials catered for beginners
- Remix – this is an online dev environment to compile and deploy smart contracts. It’s a good starting point as it is easy to use. This allows you to focus on learning the language rather than CLIs, IDEs, testing frameworks, and all the other stuff
The way to think about smart contracts is that they are just like any other program but with some interesting properties:
- They’re deterministic, meaning there is no notion of randomness (pseudo-randomness, yes). The same input must always produce the same output
- They’re open source so anyone can see your code
- They live on an address and hold funds, just like a wallet
- Reading data from a smart contract is free
- Writing data to a smart contract is a transaction, which has a cost associated with it based on how computationally complex the logic is of what you’re doing
- Smart contracts can interact with each other. Think of existing smart contracts as “LEGO blocks” you can build off. Example: you have a dApp that buys token X on Uniswap when you interact with it.
- They are immutable (mostly). You can’t patch a smart contract on the fly. Once it is out there… it’s out there. I often intuit deploying smart contracts as similar to launching a rocket (or throwing a frisbee…).
- In case you’re not familiar with the term, deployment is the act of putting a smart contract on the blockchain, much like publishing a book.
Approaching Solidity as a Developer
It’s a statically typed language (because smart contract transactions are deterministic) designed for object oriented programming. It might appear to be high level like Java at a first glance, but it is more similar to C++ in terms of how granular you can get with memory management. In particular, variables either exist in storage (on the blockchain), memory (on the stack, in your transaction), or as calldata (inputs to a transaction). Learning the basics of Solidity is easy. But optimizing gas and creating secure contracts will require that low level understanding of the language.
Here are some additional resources to dig into:
- The Solidity Docs – They’re very robust and updated regularly
- OpenZeppelin – OpenZeppelin is an audit company that has open source contracts for the core building blocks of smart contract development (tokens, access control, etc.) that are widely used in reputable projects. Think of them as the gold standard for smart contracts. Don’t reinvent the wheel when you don’t need to
- Brownie – this is a testing framework for those with a Python background
- Foundry – this is a relatively new testing framework that I’m in the process of learning how to use. It allows you to write unit tests in Solidity, avoiding the context switching to another language. It’s also written in Rust, making it super fast!
- Solidity Visual Developer – this is a great VSCode extension for Solidity development. It does many things such as generating diagrams and flattening your contracts (to publish to Etherscan)
The development process is different from traditional web2 applications. There’s not as much of a culture around CI/CD, given the stakes of deploying a smart contract. When you’re building an application that will have millions of dollars of value stored in it, you can’t move fast and break things. Almost every week there’s a new technical vulnerability resulting in funds being drained. As a result, you’ll often be spending more of your time testing than actually writing smart contract code.
However, a lot of web2 concepts have web3 parallels. When you connect smart contracts to other smart contracts, it’s very similar to an API call, with the smart contract address being the URL and the interface and function being the request payload format. You also always want to make things more efficient, as inefficiency here has a direct financial cost to your user base. A couple of small changes can make a substantial difference when gas prices are high; bringing a transaction down from $20 to $10 makes it much more accessible.
Solidity is a nascent language and blockchain is a nascent technology. As a result, many of the standards and best practices are still being worked out. But that’s exciting – you’ll be working with cutting edge technology and deploying your first smart contract in no time!
It’s a beautiful language that is accessible for beginners and intellectually stimulating for experienced engineers. It’ll be tough in the beginning, but if it wasn’t tough everyone would be doing it. Happy coding!