How to Learn Solidity: All You Need To Know
Solidity has driven many developers to enter the world of web3 for the very first time – and for hundreds of thousands of good reasons: it's an insanely lucrative field (with six-figure salaries straight off the bat), the demand for web3 professionals far outstrips the supply, and major industries are leveraging the technology and driving disruptive innovation across all sectors.
It's not surprising that web developers are adding smart contract programming languages and the web3 stack to their arsenal. If you've been wondering how to get into web3 and the stack that powers it, and more specifically, how to learn Solidity – web3's pre-eminent programming language – then you've come to the right place.
What is Solidity?
Solidity is the programming language that powers Ethereum. It's the programming language responsible for expanding the possibilities of blockchain technology beyond mere cryptocurrency to becoming the world's computer.
Ethereum co-founder Gavin Wood first proposed the development of the language in 2014, to serve as the infrastructure of the self-automated smart contracts that run at the core of the second-largest cryptocurrency by market capitalization.
Decentralized apps (dapps), non-fungible tokens (NFTs), decentralized finance (DeFi), blockchain-based games, and decentralized autonomous organizations (DAOs) are all essentially complex Solidity smart contracts. Web3 developers create smart contracts, or basically blockchain apps, that run on the distributed ledger using Solidity.
In essence, anything and everything that the Ethereum virtual machine (EVM) can run can be – and already largely is – created using the programming language.
Thousands of developers are building the infrastructure for the new era of the internet using web3 technologies to create blockchain-enabled services.
Let's go on a deeper dive into how to learn Solidity so you know exactly what skills you need to take your talents to web3.
What are the main advantages of Solidity?
One of the main advantages of Solidity is that anyone with a basic knowledge of programming languages (C++ and JavaScript come to mind) can use the language. This quality is what helped unlock the potential of Ethereum and turn it into a web3 colossus.
Solidity is also built on a distributed ledger, so smart contracts built using it cannot be edited or tampered with. That makes Ethereum an extremely secure way to perform its main function – to transfer value using Ethereum tokens or its ecosystem of ERC-20 tokens to fund such exchanges of value.
What are the main disadvantages of Solidity?
One of the drawbacks of Ethereum's immutability is that any smart contracts written using Solidity should be impeccably prepared. "Code is law" isn't an adage in web3 for no reason. Therefore, writing smart contracts that are airtight is of paramount importance in the web3 space. Developers in this niche need to test and deploy smart contracts that are immaculate and audited for optimal security.
Any errors inherent in the smart contract cannot be corrected, any transactions cannot be reversed, and any potential exploits can only be addressed by upgrading Ethereum code entirely, which requires massive and time-consuming effort from the individual nodes that comprise the ecosystem.
The latter was the case with the 2016 DAO hack that drained approximately $60 million worth of Ethereum blockchain. This led to a highly controversial fork to return the stolen funds from The DAO and give it back to its investors.
How long does it take to learn Solidity?
Solidity is an object oriented programming language created for and mainly used on Ethereum. Object-oriented programming languages like Solidity enables developers to build computer programs using prebuilt code snippets.
Solidity is a high-level language, meaning it is designed to be as close to human language as possible. That makes Solidity easy to understand. Anybody with a basic familiarity with traditional web2 programming languages such as JavaScript, Java, Python, and C++, for instance, will find the core concepts of Solidity familiar, thus shortening the time it takes to learn Solidity. Learning Solidity can take anywhere from one to six months. This opens the door to pursuing a specialization in a full stack blockchain development career.
Currently, developers who wish to break into web3 can learn Solidity in three ways:
- Metacrafters. Our online courses on Solidity combine the structure and order of boot camps with the self-paced learning that tutorials offer. With our proof-of-learn and learn-to-earn mechanisms, Metacrafters is the best point at which you can start your learning journey. Our online courses follow all the rigor of a bootcamp and clearly defined learning milestones to ensure learners' progress, while quizzes, assignments, and tests help test their knowledge as they progress through the ranks.
- Bootcamps. If you find you learn better in an organized, immersive learning environment, joining a Solidity bootcamp might just be for you. These bootcamps offer intensive courses, hands-on training, and professional oversight to help you become a full stack blockchain developer before long.
- Tutorials. If you're more of an autodidactic self-starter who learns at your own pace, there are plenty of high-quality online Solidity tutorials for both beginners and experienced developers. There are dozens of tutorials on the official Ethereum blockchain developer resource covering Solidity, ranging from the basic concepts of smart contracts to more advanced topics such as gas fee optimization.
If you're a complete beginner without a lick of coding experience, it would be helpful to take free foundational courses about web3, blockchain technology, smart contracts, and technical terms that will help broaden your foundation. Web development is constantly evolving, and the majority of devs and software engineers are proponents of lifelong learning.
A good example of a free and fun way to learn Solidity is by playing CryptoZombies, a free platform that reinforces blockchain concepts and Solidity through gaming. The game enables players to familiarize themselves with basic to intermediate smart contract design and serves as a jump-off point to learning more advanced Solidity concepts.
We've put together a list of the most important Solidity concepts as follows.
How to Learn Solidity: Important Core Concepts
Regardless of whichever learning method you choose, you'll want to learn these core concepts of Solidity in order to write flawless code every single time.
Solidity Application Binary Interface (ABI)
The Solidity ABI is a set of definitions that we use to interact with smart contracts and crypto wallets. It enables two entirely different pieces of software to communicate with each other.
The ABI essentially allows you to create code that can interact with any kind of contract whether you possess the source code or not. This is made possible by all the information the ABI has that is required to decode and encode data transmitted between smart contracts.
Smart Contracts
a term used to describe computer code that automatically executes all or parts of an agreement and is stored on a blockchain-based platform
Smart contracts are pieces of code deployed on the Ethereum blockchain that automatically executes all or parts of an agreement when a certain set of criteria are met. Smart contracts can be used to create cryptocurrencies, dapps, NFTs, and a whole lot more.
ERC-20 tokens are a common smart contract use case. Examples of complex smart contracts include yield farming, lending, synthetic assets, and token swaps. These smart contracts are developed using a Solidity compiler that converts the code into a collection of bytecodes used to deploy them.
ERC-20 Tokens
ERC-20 is the technical standard for fungible tokens that represent real-world assets such as fiat currencies or commodities on the Ethereum blockchain.
Every Solidity developer should learn how to create ERC-20 tokens considering they are the most prevalent digital asset type on Ethereum. It's also among the easier smart contracts to write, so mastering the skill is a definite advantage.
Contract Interface
Interfaces serve as the backbone of smart contracts. They specify the contract's functionalities and how they are set off. They also enable developers to create smart contracts that can be extended and reused. For instance, you could create a contract interface for a token. From that point forward, any contract that implements the said interface can be used as another token.
Interfaces describe all functions an object must possess for it to work. They enforce a defined set of functions and properties on smart contracts.
Functions
Functions, which are snippets of code that receive inputs, execute an action, and give back an output that plays a key role in Solidity.
Functions enable Solidity smart contracts to run all kinds of actions, whether storing data, sending tokens, or staking tokens inside a smart contract. A group of actions meant to be reused in a variety of actions is called a library.
Visibility of Functions
Solidity functions contain visibility settings that determine who can see and run the said function. Four visibility options are available in Solidity: public, private, external, and internal.
Public functions can be accessed, seen, and run by anyone. Private functions can only be seen and performed by the smart contract wherein it is contained. External functions, meanwhile, can be accessed and seen by anyone, but can only be run by other smart contracts. Lastly, internal functions can only be seen and run by other functions that the same smart contract possesses.
Call Function
The call function enables you to run code inside another smart contract. Call functions enable smart contracts to communicate with each other in the Ethereum ecosystem. They enable you to write smart contracts that can interact with any other smart contract, whether you possess the source code or otherwise. This is made possible by the Application Binary Interface (ABI), which already has all the information it needs to process and decode data sent between smart contracts.
Delegatecall Function
The delegatecall function works similarly to the call function, but with one key difference: it performs the code within the context of who is calling the function. What this means is that any changes made by the called contract as far as any storage changes are concerned will be executed on the caller's storage.
Delegatecall functions essentially enable you to write smart contracts that are reusable by other smart contracts.
Modifiers
Modifiers also work similarly to functions, with several key differences. One is that modifiers can only be used on functions. Second, modifiers are called before the contract runs the function. For instance, a payable, which is a type of modifier, allows a particular function for the smart contract to accept a particular amount of Ethereum.
Modifiers enable you to change a function's behavior without modifying the actual underlying code. Another example of how modifiers work is that they can check whether a user has enough cryptocurrency balance before running a function or before adding an event that is triggered when the call function is activated.
Arrays
Arrays store values of a data type in sequential order in memory. This can be a list of names or numbers. In Solidity smart contracts, arrays can be of fixed or dynamic size. Dynamic array sizes aren't predefined when they are declared, as opposed to fixed arrays which possess predefined inputs.
Structs
Structs are creative data structures in Solidity that enable you to store data inside a Solidity smart contract. They are similar to arrays, but structs may have different, more complex data types with multiple properties.
Mappings
Mappings, similar to arrays and structs, are another way to store data within a Solidity smart contract, but the keys aren't restricted to just integers, but other key types. Mappings are more versatile and robust as a result of this feature. They help you store data within a contract in an easy-to-use, flexible manner.
Events
Events enable automated code execution upon reaching certain conditions as stipulated within a smart contract. For instance, a developer can program an event triggered when a transaction is confirmed on the blockchain, or when a user performs a particular action. Events on Solidity enable developers to write smart contract code that is triggered to execute based on real-world events, which is how many dapps interact when certain conditions are met.
Error Handling (the "require" keyword)
The "require" keyword is comprised of three key functions: require, assert, and revert. The "require" keyword is responsible for verifying the veracity of whether a condition is true or false. If a condition isn't met or isn't true, the smart contract will automatically reverse the transaction and produce an error message. Ultimately, using require enables you to troubleshoot your smart contract and prevent errors from occurring.
Upgradeable Smart Contracts
This is a contract type that may be upgraded without needing to redeploy the smart contract itself. Upgradeable smart contracts enable you to edit a contract and make changes to it after it has been deployed on-chain without affecting any existing data that has already been deployed on the blockchain.
Proxy Contracts
Proxy contracts are a contract type that enables other contracts to run their code. These proxy contracts are useful in situations wherein you wish to upgrade a contract without having to redeploy it.
They are also useful whenever a developer wants to execute a smart contract's code on another blockchain.
Multi-sig Contracts
As their name implies, a multi-sig contract is a contract type that requires more than just one signature to run its code. Mulitsig contracts on Solidity are very useful when developers wish to require several individuals to approve a transaction before it is performed. This includes limiting the amount of cryptocurrency that can be spent for a certain time frame.
Reentrancy Attacks
Reentrancy attacks are an exploit that can happen between two smart contracts, such as when an attacking contract calls another vulnerable smart contract and exploits its code to drain it of all its funds.
More specifically, they happen when an attacking contract calls another smart contract, and then the second contract calls back to the attacking contract or another contract, usually before the attacking contract has completed executing. This is exactly what happened in the DAO hack of 2016 which created the Ethereum Classic fork.
The final word on learning Solidity
Whatever your goals are in learning Solidity, there is always an option that's suited to your exact needs. Free tutorials are a great option to begin, while Metacrafters can give you more direction and structure in your learning.
Once you've decided on how you wish to learn, it's important to get the fundamentals of Solidity smart contracts down pat – if you're reading this sentence, you will have built a solid foundation from whence to become a fluent Solidity developer in the years to come.