What is Solidity?
As the web3 industry grows, developers are met with more choices of web3 programming languages. Each language is designed with different benefits and tradeoffs for writing smart contracts. Languages may differ through supporting specific blockchains, or have different characteristics such as speed, readability, or security.
Developed as the smart contract language for the Ethereum blockchain, Solidity is a powerful programming language that is used to create decentralized applications (dApps) for the largest developer ecosystem in the blockchain industry.
In this article, we will provide an introduction to Solidity through its history, its language influences, and its uses. At the end, we will provide some of the best developer resources so you can continue learning about Solidity development.
What is Solidity?
This section introduces you to the history of Solidity, establishes similarities between Solidity and other programming languages, and explains the main use cases for Solidity.
Who created Solidity?
In 2014, the CTO of Ethereum, Gavin Wood, came up with Solidity as a language that would satisfy Ethereum’s need for a Turing-complete programming language for writing smart contracts.
The founder of Ethereum, Vitalik Buterin, proposed Ethereum as a protocol that would extend the blockchain functionality pioneered by Bitcoin, with the added functionality of smart contracts. In his vision, Ethereum would be able to run an elaborate network of smart contracts, which are conditionally executing pieces of code that run on a distributed, global network of computers. Smart contracts enable developers to create new cryptocurrencies, build DeFi apps, and much more.
The Solidity project team was led by Christian Reitwiessner, and they were successful in creating a Turing-complete, object oriented programming language for implementing smart contracts. Being a high-level language means developers create smart contracts without having to manipulate system-level information like memory or bytecode to perform computations.
Turing completeness refers to the ability of a data-manipulation system, in this case a programming language, to simulate the behavior of a Turing Machine. Theoretically, Solidity needed to be able to perform any computation developers could require of it.
On what programming languages is Solidity based?
Solidity Similarities to C++
Solidity uses an identical syntax to C++ for variable declarations and for loops. Additionally, there is support for C++ style function overloading, which is needed when two functions have the same name but differ in the parameters they accept.
Finally, Solidity allows both implicit and explicit type conversion. This means variable types can be cast by explicit developer code or will be automatically converted if required by a computation.
For developers familiar with some of Solidity’s greatest influences, getting to know Solidity will be fairly straightforward. Additionally, Solidity is statically typed, allows the use of libraries as well as the creation of complex types.
Solidity Similarities to Python
Solidity’s influence from Python is less apparent in terms of syntax, however, like Python, Solidity uses C3 linearization, multiple inheritance, and maintains the ‘super’ keyword.
Using Pythonic syntax, Vyper is similar to Solidity, and is purposefully designed to increase the security of smart contracts used on EVM-compatible blockchains.
How is Solidity used?
Specific to its nature as a blockchain coding language, Solidity was created to expressly be compiled on the Ethereum Virtual Machine (EVM). As such, Solidity is able to write secure Ethereum-compatible smart contracts, for any EVM-compatible blockchain.
This broad compatibility, paired with its easy understandability and flexible functionality, has led Solidity to be the most widely used blockchain development language in the industry.
How does Solidity work?
Solidity developers write smart contracts, which are programs running on the EVM. Similar to classes in other languages, smart contracts can have multiple functions, internal states and public declarations.
Solidity contracts are compiled into bytecode to be read by the EVM. After compilation, the Solidity contracts will look no different from those written in other EVM smart contract languages like Vyper or Huff.
Like any other developer tool, Solidity goes through regular version updates. Note that because smart contracts are deployed once and are irreversible after joining the blockchain, Solidity version constraints will only matter at the time of creation.
While Solidity developers can theoretically write Ethereum smart contracts directly in bytecode, high-level languages like Solidity allow engineers to write contracts more efficiently without any low-level manipulation.
How does Solidity interact with the EVM?
The following is a summary of how Solidity works to change the state of the EVM:
- Write smart contracts in Solidity
- Solidity smart contracts are compiled to bytecode
- Bytecode is converted into EVM opcodes
- EVM opcodes alter the state of the EVM
The EVM is a virtual state machine and record keeper for Ethereum’s “global computer.” In the simplest terms, the EVM maintains the global state of the network, which includes addresses, account balances and token holdings.
Solidity smart contracts are written to make changes to the EVM’s global state. The EVM’s global state is changed by actions such as minting tokens, sending and receiving tokens, or releasing assets.
A host of EVM operations, encoded into EVM opcodes, prompt these changes to the global state. Each EVM opcode is designed to prompt the EVM to perform a specific kind of state change, such as sending tokens from one address to another, minting tokens, or even destroying smart contracts.
In the last step, the EVM translates the smart contract’s bytecode into EVM opcodes, which make the necessary changes to the blockchain.
Each opcode comes with a certain gas fee, charged in ETH to mitigate the risk of a malicious actor clogging up the network with an inordinate amount of requests. The total gas cost of a transaction is thus calculated by the price per unit of gas times the total gas cost of a transaction’s opcodes.
What EVM-compatible blockchains support Solidity?
Solidity is able to write smart contracts for any EVM-compatible blockchains, including L2s such as Polygon, Arbitrum, and Optimism. Since Solidity is flexible and easy to use, it is supported by a large number of other blockchains. Here are some of the largest projects that support Solidity:
Polkadot is a chain focused on integrating multiple blockchains (i.e. parachains) into one chain using a relay chain. Polkadot’s goal is for parachains to be interoperable to allow scalability and increase bandwidth. One example of a Polkadot parachain is Astar, which is supported by Alchemy.
Avalanche is an Ethereum competitor that supports Solidity development. The Avalanche architecture is based on a network of three blockchains: one for issuing and trading assets (X Chain), one for coordinating the network’s validators (P-Chain), and one that allows smart contract creation (C Chain).
3. BNB Chain (Formerly Binance Smart Chain)
Binance Smart Chain started as an ERC-20 token on Ethereum, and to support their growing ecosystem of dApps, the Binance Smart Chain (BSC) network was created. BSC and its tokens use Solidity in their smart contracts. Today, Binance Smart Chain is called BNB Chain.
How popular is Solidity?
Solidity is the most popular smart contract programming language in the blockchain industry. Solidity is the native language for creating EVM-compatible smart contracts. Even outside of the EVM, there are projects that have built-in support for Ethereum’s Virtual Machine such as Neon Labs’ Solana EVM.
Since the blockchain industry is still growing, it may appear as if Solidity is less used compared to all other programming languages. However, within the industry, Solidity is the most widely applicable smart contract language. Solidity Has strong use cases on many chains and in the fastest growing web3 dApp ecosystems.
How is Solidity used on Ethereum?
Seeing some examples of Solidity’s use in Ethereum will give you a good sense of the simplicity of Solidity code in creating flexible smart contracts. The code examples found in the official Solidity documentation are a great introduction to the language.
The following is a simple code example from the Solidity documentation that creates a simple currency on Ethereum.
Notice the function declarations, private and public variables for the contract. Functions allow the contract to perform different actions on-chain, in this case sending tokens from one address to another, and minting tokens.
Public variables are accessible from outside the contract and automatically generate getter functions for retrieving the value of those variables. The event keyword allows client applications to listen for changes caused by the contract.
In this example, a client would see the sent event, which indicates to a listener that address msg.sender sent an amount of tokens to the address receiver.
What are Solidity ERC standards?
Underlying the design of Solidity smart contracts are ERC (Ethereum Request for Comment) standards, which are guidelines made to improve and standardize the implementations of different types of Ethereum tokens.
ERC standards are proposed by EIPs (Ethereum Improvement Proposals). Once ERC standards are approved and finalized, they become a standard for writing Solidity contracts. This allows a common Solidity interface template for building smart contracts. When Solidity developers build tokens adhering to existing ERC standards, they know how their tokens will behave appropriately on the blockchain.
Some of the most widely used ERC standards are:
- ERC-20 - fungible token standard
- ERC-721 - non-fungible token standard
- ERC-1155 - semi-fungible token standard
- ERC-4626 - yield-bearing vault standard
How to Learn Solidity Programming
So you know what Solidity is, but how do you begin learning Solidity? As the most popular smart contract language, there is a wealth of resources available online to begin learning Solidity development.
One of the best ways to learn Solidity is with Alchemy University's 7-week Solidity bootcamp, that was originally created by ChainShot, a leading team of web3 engineers, and redesigned by Alchemy after they acquired ChainShot in August 2022.
The Ethereum developer bootcamp was originally a $3,000 certification course, and is now FREE. Secure your spot in line to join Alchemy University.
This section provides you with some of the best resources online for learning Solidity development.
- Official Solidity Documentation - use docs as your primary resource for learning Solidity development.
- Solidity by Example - compilation of Solidity examples ranging from a ‘Hello World’ program to wallet applications and DeFi.
- Clean Contracts - guide on how to write safe and predictable smart contracts with Solidity code examples.
- Ethernaut by OpenZeppelin - a smart contract based war game where each level consists of hacking a smart contract.
Start Building with Solidity
This article introduced you to Solidity and provided you with resources to begin learning Solidity development. Solidity is an extremely flexible and powerful language to develop decentralized applications on Ethereum and EVM-compatible blockchains.
Once you are comfortable with your knowledge, don’t hesitate to deploy an application on the Goerli testnet, attend a web3 hackathon, and start trying to build a web3 startup!