The Best Way to Learn Solidity for Free (2022)
Solidity is an object-oriented, high-level language for programming smart contracts. Learning Solidity will allow you to create smart contracts and decentralized applications (dApps).
This article covers the most common methods to learn Solidity and introduces important Solidity concepts that students need to learn to become an Ethereum developer.
Why is learning Solidity important?
Solidity, the programming language for writing smart contracts on Ethereum and EVM compatible blockchains, is one of the most important skills for blockchain developers. As the ecosystem around Ethereum and other smart contract platforms grows, so does the demand for Solidity developers.
At the time of writing, the average salary for a remote Solidity developer is $145,000 per year, and experienced developers can earn upwards of $500,000 including employee stock options and token-based incentives. Even in bear markets, there are 1000s of Solidity job postings seeking qualified candidates.
Not only can learning Solidity provide tremendous financial opportunities, but it also allows you to build amazing dApps that can have a huge impact on the world. In fact, Ethereum alone has close to 3,000 dApps serving a range of goals from financial inclusion to sustainable energy.
Learn Solidity with a Bootcamp
If you want to learn Solidity and other blockchain development skills in a structured, immersive environment, a Solidity bootcamp might be the right option for you. Blockchain bootcamps provide intensive, hands-on training to help you become a job-ready blockchain developer.
After Alchemy acquired ChainShot, Alchemy redesigned ChainShot's 7-week, $3,000 Ethereum Developer Bootcamp, and is offering it to the public for FREE under Alchemy University. To learn Solidity with expert teachers and alongside motivated peers, secure your place in line for Alchemy University's Solidity bootcamp.
Learn Solidity with Tutorials
If you're a self-starter and want to learn at your own pace, tutorials are a great way to learn Solidity. There are many high-quality Solidity tutorials available online, ranging from beginner to advanced levels.
The official Ethereum developer resources include 53 tutorials tagged "Solidity," covering everything from the basics of smart contracts to more advanced topics like gas optimization and secure signing.
Learn Solidity with Online Courses
Online courses are a great way to learn Solidity if you want more structure and guidance than tutorials provide. There are many high-quality Solidity courses available, both free and paid from web3 startups and web2 platforms like Udemy.
While tutorials are self-paced, online courses often have set lessons and deadlines, providing time-bound motivation for learners to stay on track. In addition, courses often include quizzes and other assignments to test your knowledge as you progress.
Important Solidity Concepts to Learn
Once you've chosen your learning method, it's time to start learning how to code in Solidity. A number of core Solidity concepts are important to understand to write effective code.
The Application Binary Interface (ABI) is a set of rules that allows two different pieces of software to interact with each other. In the context of Solidity, the ABI allows smart contracts to interact with each other, as well as with external software like wallets.
The ABI allows you to write code that can interact with any contract, regardless of whether you have the source code or not. This is possible because the ABI includes all the information needed to encode and decode data that is passed between contracts.
A smart contract is a piece of code that runs on the Ethereum blockchain and performs certain actions when a set of conditions are met. Smart contracts can be used to create digital tokens, decentralized applications (dApps), and more.
A common smart contract use case is creating an ERC20 token, which can be done in just a few lines of code. More complex smart contracts include token swaps, yield farming, and synthetic assets. These contracts are compiled using a Solidity compiler, which outputs bytecode used to deploy the contract.
ERC20 tokens are a type of digital asset that runs on the Ethereum blockchain. They are often used to represent real-world assets, such as commodities or fiat currencies.
ERC20 tokens are the most common type of digital asset on Ethereum. Since ERC20 tokens are also one of the easiest types of contracts to write, learning how to creating them is an important skill to master.
An interface is a way to specify what functions a contract must have. Interfaces allow you to create contracts that can be easily reused and extended. For example, you could create an interface for a token contract, and then any contract that implements that interface can be used as a token.
Inheritance is a way to reuse code in Solidity. Inheritance allows you to create "child" contracts that inherit all the code from a "parent" contract. This lets developers avoid duplicating code and makes smart contract maintenance much easier.
Inheritance is an important concept in object-oriented programming, and it's one of the things that makes Solidity so powerful. Learning how to to create standardized contracts that can be easily extended and modified is an important Solidity lesson to master.
As with any programming language, functions are a key part of Solidity. Solidity functions are pieces of code that receive inputs, performs some action, and returns an output.
Functions can be written into Solidity smart contracts to perform all sorts of actions, from sending tokens to storing data. A collection of functions intended for reuse is called a library.
A basic principle in coding is called the "D.R.Y. principle," which stands for "Don't Repeat Yourself." This principle states that developers should never write the same piece of code twice. Instead, developers should write a function once, and then call that function whenever you need to perform that action.
One important thing to note about Solidity functions is that they have visibility settings. Visibility determines who can see and execute the function. There are four visibility levels in Solidity: public, external, internal, and private.
- Public functions can be seen and executed by anyone.
- External functions can be seen by anyone but can only be executed by other contracts.
- Internal functions can only be seen and executed by other functions within the same contract.
- Private functions can only be seen and executed by the contract itself.
The call function allows you to execute code in another contract. This is how contracts interact with each other on Ethereum.
The call function allows you to write code that can interact with any contract, regardless of whether you have the source code or not. This is possible because the ABI includes all the information needed to encode and decode data that is being passed between contracts.
The delegatecall function is similar to the call method, but with one important difference; it executes the code in the context of the caller. This means that any storage changes made by the called contract will be made to the caller's storage.
The delegatecall function allows you to write contracts that can be reused by other contracts. For example, you could write a contract that implements an interface, and then other contracts can delegatecall that contract to use the interface.
Modifiers are like functions, but with some important differences. First, modifiers can only be used on functions. Second, modifiers are called before the function is executed. An example of a modifier is payable, which allows a function to receive Ether into the contract.
Modifiers allow you to change the behavior of a function without touching the actual code. For instance, a modifier could check if a user has enough balance before executing a function, or to add an event that is triggered when the function is called.
Arrays are linear data structures that store a fixed-size of elements of the same data types which are stored in contiguous and adjacent memory locations. An array can be both of fixed or dynamic size. The size of dynamic arrays are not predefined when they are declared, in contrast to fixed arrays which have a predefined size.
If developers need to iterate over a group of data (e.g. using a loop) then use an array. If there’s no need to iterate over a set of data, and instead developer can retrieve values based on a known key, then consider using mappings.
A struct is a way to store data in a Solidity contract. Structs are similar to an array, but each element can have a different type. Structs are useful for creating more complicated data types that have multiple properties.
A mapping is a way to store data in a Solidity contract. Mappings are similar to arrays, but the keys can be any type and not just integers. This feature makes mappings versatile and powerful. Mappings allow you to store data in a contract in a way that is flexible and easy to use.
Events are a way to trigger code execution when certain conditions are met. For example, developers can write an event that is triggered when a user buys a token, or when a transaction is confirmed on the blockchain.
Solidity events allow developers to write code that is executed in response to real-world events. This is how many dApps are able to interact with the real world, for example by sending an email or SMS when a condition is met.
Require (Error Handling)
The "require" keyword is one of three special functions: require, assert, and revert. Require checks if a condition is true, and if not, it will revert the transaction and return an error message.
Using require allows you to prevent errors from happening in your contract. For example, you could use require to check that a user has enough balance to make a purchase, or that an address is valid before sending a transaction.
Upgradeable Smart Contracts
Upgradeable smart contracts are a type of contract that can be upgraded without the need to redeploy the contract. Upgradeable smart contracts allow you to make changes to a contract after it has been deployed, without effecting any of the data or code that is already on the blockchain.
A proxy contract is a type of contract that allows another contract to execute its code. Solidity proxy contracts are useful for cases where you want to upgrade a contract but don't want to redeploy it.
Proxy contracts are also useful when developers want to execute a contract's code on a different blockchain. For example, you could use a proxy contract to execute a Solidity contract on an Ethereum testnet.
A multisig contract is a type of contract that requires more than one signature to execute its code. Solidity multisig contracts are useful when developers want to require multiple people to approve a transaction before it is executed.
Multisig contracts are also useful for cases where developers want to limit the amount of money that can be spent in a certain period of time. For example, you could use a multisig contract to require two signatures for any transaction over $1,000.
Reentrancy attacks are a type of attack that can occur in Solidity contracts when a contract calls another contract, and then the second contract calls back into the first contract or another untrusted contract, typically before the first contract has finished executing.
Reentrancy attacks can be used to exploit vulnerabilities in contracts. For example, an attacker could use a reentrancy attack to drain all the Ether from a contract.
The Best Way to Learn Solidity
No matter what your goals are, there is a way for you to learn Solidity that fits your needs. If you're looking for a quick and easy way to get started, tutorials are a great option. You can also check out our introduction to Solidity. If you want more structure and guidance, online courses might be a better fit. And if you're looking for an immersive, hands-on experience, a bootcamp could be the right choice.
Once you've chosen your learning method, there are a number of important concepts to ensure you get down, including smart contracts, functions, events, and more. By understanding these concepts, you'll be well on your way to becoming a proficient Solidity developer.