Back to blogs
Written by
Pari Tomar
Published on
August 22, 2024

What is Solidity?

Solidity is a high-level programming language designed for writing smart contracts. It is the standard for smart contract development on most EVM-compatible blockchains.

Table of Contents

Since its introduction, the Solidity programming language has become the default choice for writing smart contracts. It is the standard for smart contract development on most EVM-compatible blockchain networks, including Avalanche, Polygon, and Binance Smart Chain.

Solidity is a high-level programming language designed specifically for writing smart contracts. These smart contracts are self-executing programs that define and enforce the rules and behaviors of accounts within blockchain networks.

Solidity developers earn an average salary of $105,000 per year, and the demand for their expertise is rapidly increasing.

Therefore, in this article, we will explore what Solidity is, its background, how it works, its various frameworks, and the resources available for learning Solidity and becoming a Solidity Developer.

Overview of Solidity

Solidity is a high-level, statically typed programming language designed for writing and deploying smart contracts on the Ethereum Virtual Machine (EVM) and other compatible blockchain platforms.

This language is an important tool for developers building decentralized applications (dApps) that require secure and transparent operations.

Turing completeness and its implications

It is a Turing-complete language, meaning it can perform any computation that a Turing machine can, given sufficient resources such as time and memory.

This characteristic makes it powerful and versatile, allowing developers to create complex logic and functionalities within smart contracts.

Key features and designs

Solidity was designed with several key goals in mind, aiming to balance ease of use with powerful capabilities, such as:

  • Contract-Oriented Design: Explicitly built for writing smart contracts, making it straightforward to define contract structures, state variables and functions.
  • Static Typing: Enforces type checking at compile-time, reducing runtime errors and enhancing code reliability.
  • Support for Inheritance: Supports inheritance, allowing developers to create modular and reusable code.
  • Libraries and Interfaces: Provides support for defining and using libraries and interfaces, promoting code modularity and reuse.

Events and Logging: Provides event handling capabilities, and enables contracts to emit events that can be logged and monitored by external applications.

Inspiration from existing languages

Solidity’s syntax and features draw inspiration from existing languages, making it accessible for developers:

  • Solidity borrows its curly-bracket syntax and many control structures, such as if, for, and while loops, from Javascript.
  • The language includes concepts such as function overloading, inheritance, and user-defined types from C++. Variable declarations and explicit type conversions are also reminiscent of C++.
  • Solidity’s modifier feature was inspired by Python’s decorators, allowing developers to alter the behavior of functions. Additionally, Solidity’s multiple inheritance and the super keyword are influenced by Python.

History of Solidity

Origins and initial development

Solidity was introduced in 2014 by Gavin Wood, the co-founder of Ethereum, and developed by Christian Reitwiessner and several other core contributors.

The language was created to use the Turing-complete capabilities of the Ethereum Virtual Machine (EVM) that could facilitate the development of smart contracts on the Ethereum blockchain.

As an open-source, community-driven project, Solidity is governed by a core team sponsored by the Ethereum Foundation

Over time, it has become the primary language for writing smart contracts on the Ethereum blockchain, continuously evolving with regular updates that introduce new features and improvements.

Evolution and current status

The language has undergone substantial development since its introduction. Ongoing development has introduced numerous features and improvements.

2014: Gavin Wood and Christian Reitwiessner led the development of Solidity to address the need for a programming language that could create smart contracts on Ethereum.

2015: The first stable release of Solidity coincides with the launch of the Ethereum mainnet.

2016-17: Rapid adoption by developers and the introduction of tools like Remix, which made smart contract development more accessible and efficient.

2018-Present: Continuous updates and enhancements, including security improvements and optimization features. The language has also integrated new capabilities through Ethereum Improvement Proposals (EIPs), allowing the community to propose and implement changes.
During this time, Hardhat was launched, further improving the development workflow with a powerful framework.
More recently, Foundry was introduced, offering a fast and efficient framework for developing and testing smart contracts.

Solidity has been increasingly adopted by other blockchain platforms like Avalanche, Polygon, and Binance Smart Chain.

How does Solidity work?

Writing and compiling solidity code

Developers write smart contracts in Solidity using its specific syntax to define contract logic, state variables, and functions.

After writing the code, it is compiled using the Solidity compiler (solc), which translates Solidity code into bytecode that the EVM can execute.

ABI and Bytecode generation

The Solidity compiler generates two critical outputs:

  • Bytecode: The compiled version of the Solidity code, consisting of low-level machine instructions that the EVM executes.
  • ABI (Application Binary Interface): A JSON file describing the contract’s functions, input/output types, and events. The ABI is required for interacting with the contract from external applications.

Interaction with the Ethereum Virtual Machine (EVM)

The EVM is the runtime environment for smart contracts on Ethereum and other EVM-compatible blockchains like Polygon and Arbitrum. It executes the compiled bytecode and manages their state on these networks, ensuring that contract logic is executed correctly as transactions are processed..

  • When a Solidity contract is deployed to any EVM-compatible network, it is assigned a unique address. This address stores the bytecode of the contract on the blockchain.
  • Users interact with the deployed contract by sending transactions to its address. These transactions can call the contract’s functions, which can modify the contract’s state or execute specific logic.
  • The EVM reads the bytecode stored at the contract’s address and executes the corresponding instructions. This may involve reading from or writing to the contract’s storage, performing calculations, or interacting with other contracts.
  • Each operation executed by the EVM consumes gas, which is paid in Ether (ETH) or the native currency of the specific chain. More complex operations require more computational effort and therefore consume more gas.

Applications of Solidity

Solidity has enabled the creation of a wide range of decentralized applications (dApps) and solutions across various industries. Here are some of the most notable applications of Solidity:

Decentralized finance (DeFi)

  • Decentralized Exchanges (DEXes): Platforms like Uniswap and SushiSwap facilitate direct cryptocurrency trading.
  • Lending Protocols: Services like Aave and Compound offer decentralized lending and borrowing.
  • Stablecoins: Tokens such as DAI.

Non-fungible tokens (NFTs)

Blockchains supporting Solidity

While Solidity was initially developed for Ethereum, its popularity and versatility have led to its adoption by several other blockchain networks. These blockchains support Solidity, allowing developers to write and deploy smart contracts across multiple platforms:

ZKsync logo and wordmark.

ZKsync

ZKsync is a Layer 2 scaling solution for Ethereum that uses zero-knowledge proofs to provide fast and low-cost transactions while maintaining Ethereum’s security.

Arbitrum logo and word mark.

Arbitrum

Arbitrum is an optimistic rollup that supports EVM-compatible smart contracts. It enhances Ethereum’s performance by enabling faster and cheaper transactions while maintaining security through rollups.

Optimism logo

Optimism

Optimism is also an optimistic rollup for Ethereum that uses fraud proofs to increase transaction throughput and reduce costs. 

Solidity frameworks and development tools

Solidity development has grown in popularity, and developers have access to various frameworks that provide additional support and tools for building, testing, and deploying smart contracts safely and efficiently.

Here are some of the most widely used frameworks and development tools:

Remix IDE logo and word mark

Remix

Remix is a browser-based Integrated Development Environment (IDE) that requires little setup and is readily available for anyone interested in writing smart contracts.

It is often the starting point for new Solidity developers.

Remix features

Remix includes various tools for development, including a workspace, compiler, and debugger. It can also be configured to deploy to most major remote procedure call (RPC) services.

Remix’s ecosystem

Besides the online IDE, Remix offers a desktop IDE and a Visual Studio Code plugin, providing additional functionality and more secure local life storage.

Hardhat logo

Hardhat

Hardhat is a JavaScript-based framework created by the Nomic Foundation, designed to help developers manage and automate the development of smart contracts.

Hardhat features

Hardhat comes with tools for compiling, deploying, testing, and debugging Solidity smart contracts. It includes a local Ethereum network for testing and supports a wide range of plugins.

Hardhat plugins

Hardhat boasts numerous open-source plugins, including gas analyzers, unit test coverage reports, and tools for integration with front-end applications.

Foundry logo

Foundry

Foundry is a rapidly growing framework known for its speed and extensive toolset.

It's designed to simplify and accelerate the process of developing, testing, and deploying smart contracts, helping developers manage the entire lifecycle of Solidity smart contracts efficiently.

Foundry components

  • Forge: Used for contract compilation, deployment and testing.
  • Cast: Facilitates transaction creation, blockchain interaction, and data conversion.
  • Anvil: A local Ethereum network for testing and debugging contracts.
  • Chisel: A Read Evaluate Print Loop (REPL) to quickly allows to write and execute Solidity code from the terminal.

Foundry language

Foundry is written in Rust, and its unit tests are written using Solidity, ensuring that all smart contract-related development uses the same language.

Foundry performance

Foundry is noted for its fast compilation and testing times compared to other frameworks.

ZKsync foundry

ZKsync Foundry is a specialized extension of Foundry that integrates with ZKsync. This tool allows developers to deploy and test contracts on ZKsync, offering faster and cheaper transactions.

Foundry also supports other blockchains like Starknet, offering similar integrations for their unique features.

Other common solidity tools

Several tools enhance the functionality and efficiency of these frameworks:

OpenZeppelin and upgrades plugin

OpenZeppelin is a smart contract library that provides smart contracts for standards like ERC20 and ERC721, as well as tools for upgrading smart contracts.

Aderyn

Aderyn is a rust-based solidity smart contract static analyzer designed to help protocol engineers and security researchers find vulnerabilities in Solidity codebases. 

Solidity VSCode extension

The Solidity VSCode extension adds support for Solidity to Visual Studio Code. It includes features like syntax highlighting, code completion, and inline compilation, making it easier for developers to write and manage Solidity contracts within the popular IDE.

Additional tools for Solidity development

Beyond the core Solidity tools, several additional tools are used for deploying and managing smart contracts on the blockchain.

Faucets

Faucets provide free testnet Ether or other tokens, enabling developers to deploy and interact with smart contracts on test networks without using real funds. A popular option is the Ethereum Sepolia Faucet, which is widely used in the Ethereum ecosystem.

Node providers

Node providers like Infura, Alchemy, and QuickNode offer scalable infrastructure for interacting with Ethereum and other blockchains.
These services provide developers with easy access to the blockchain network, enabling them to deploy contracts, read blockchain data, and send transactions without running their own nodes.

Smart contract example

To understand how Solidity is used in practice, let’s look at a simple example of a smart contract that implements a basic token. This contract allows the creator to mint new tokens and users to send tokens to each other.

Please note that this is a simplified example and should not be used in production.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

contract Coin {
    // The keyword "public" makes variables accessible from other contracts
    address public minter;
    mapping(address => uint) public balances;

    // Events allow clients to react to specific contract state changes
    event Sent(address from, address to, uint amount);

    // Errors allow you to provide information about why an operation failed
    error InsufficientBalance(uint requested, uint available);

    // Constructor code is only run when the contract is created
    constructor() {
        minter = msg.sender;
    }

    // Sends an amount of newly created coins to an address
    // Can only be called by the contract creator
    function mint(address receiver, uint amount) public {
        require(msg.sender == minter);
        balances[receiver] += amount;
    }

    // Sends an amount of existing coins from any caller to an address
    function send(address receiver, uint amount) public {
        if (amount > balances[msg.sender])
            revert InsufficientBalance({
                requested: amount,
                available: balances[msg.sender]
            });

        balances[msg.sender] -= amount;
        balances[receiver] += amount;
        emit Sent(msg.sender, receiver, amount);
    }
}

Explanation of the Solidity smart contract

  • Minter: The address of the contract creator, who has the authority to mint new coins.
  • Balances: A mapping that keeps track of the balances of all users.
  • Events: The Sent event logs the details of coin transfers.
  • Constructor: The constructor is a special function that is executed only once, when the contract is deployed. The constructor sets the minter to the address that deploys the contract.
  • Mint Function: The mint function allows the minter to create new tokens and update the balance of a specific address.
  • Error Handling: The InsufficientBalance error is used to handle cases where a user tries to send more tokens than they have.
  • Send Function: The send function enables users to transfer tokens to another address, provided they have sufficient balance.

Workflow

  1. The contract is deployed to an EVM-compatible network, with the deployer becoming the minter.
  2. The minter creates and distributes new coins to specific addresses using the mint function.
  3. Users transfer tokens to others via the send function, which triggers the Sent event to log the transaction.

While this example demonstrates a basic token contract, ERC standards standardize common smart contract patterns and allow developers to write interoperable smart contracts. 

ERC standards

ERC (Ethereum Request for Comment) standards are technical specifications that define a set of rules for various functionalities on the Ethereum blockchain. These standards define a set of rules that tokens must follow if they are to be used across various decentralized applications (dApps) and platforms within the Ethereum ecosystem.

Here are some of the most widely used ERC standards:

ERC-20

ERC-20 is the standard for creating fungible tokens. Fungible tokens are identical and interchangeable, examples include DAI and USDC.

The ERC-20 standard provides rules for:

  • Token transfers from one address to another.
  • Enabling the checking of token balances for addresses.
  • Letting users approve other addresses to transfer tokens on their behalf.
  • Emitting events for transfers and approvals that external applications can track.

ERC-721

ERC-721 is a standard for creating non-fungible tokens (NFTs). Unlike fungible tokens, each NFT is unique and cannot be exchanged on a one-to-one basis. ERC-721 represents ownership of specific items, such as digital art or collectibles.

Key aspects include:

  • Each token has a unique identifier and metadata.
  • Tokens are owned by addresses and can be transferred.
  • Allowing tokens to be approved and transferred, similar to ERC-20, but for unique items.

ERC-1155

ERC-1155 is a multi-token standard that supports both fungible and non-fungible tokens within a single contract. It is efficient and flexible, enabling:

  • Perform multiple token transfers in a single transaction, including different token types.
  • Minimize gas costs by bundling multiple token types into a single contract.
  • Manage fungible and non-fungible tokens within one contract.
  • Assign distinct metadata to each token type for enhanced functionality.

Security consideration

Despite its success, Solidity has faced challenges and limitations, both as a language and as part of the Ethereum ecosystem.

Ensuring the security and correctness of smart contracts is crucial; any bug or vulnerability can result in irreversible losses or attacks, such as the vulnerability in the DAO smart contract in 2016, which led to the Ethereum blockchain’s hard fork.

The immutability of smart contracts builds trust but also makes them susceptible to vulnerabilities. Any mistake in the code or oversight in security can lead to irreversible consequences, including the loss of funds.

Code audits are essential for any application to identify and fix potential vulnerabilities. Regular code audits help ensure that smart contracts are secure before deployment.

To solve this problem, Cyfrin aims to build state-of-the-art security tools while helping the world’s biggest protocols secure their codebase and users. It provides end-to-end smart contract security services to help organizations and institutions protect users and assets from the billions of dollars lost annually to DeFi thefts.

How to learn Solidity

Learning solidity is required for anyone interested in developing decentralized applications (dApps) and smart contracts on EVM-compatible blockchains.

Here are some recommended resources and steps to get started:

1. Cyfrin Updraft

Cyfrin Updraft offers comprehensive courses on blockchain basics, Solidity development, smart contract security and more for free.

Courses include:

  • Blockchain Basics
  • Solidity Smart Contract Development
  • Foundry Fundamentals
  • Advanced Foundry
  • Smart Contract Security
  • Assembly and Formal Verification
  • Smart Contract DevOps
  • Uniswap v2

2. Solidity By Example

Solidity by Example is a collection of concise and easy-to-understand Solidity code examples. This resource is ideal for developers who prefer learning by directly working with code snippets and seeing practical implementations.

3. CryptoZombies

CryptoZombies is a gamified guide that gives step-by-step instructions and practical coding exercises to learn Solidity.

4. Documentation and guides

Solidity documentation

The official Solidity documentation provides in-depth explanations of syntax, and common patterns and uses comprehensive reference material and examples.

Ethereum

Ethereum’s official website offers tutorials, documentation, and resources for developers including beginner to advanced tutorials, developer tools, and community support.

OpenZeppelin contracts

OpenZeppelin provides a library of well-audited code of reusable and secure smart contracts.

Conclusion

Learning to code in Solidity 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.

To get started or enhance your skills, consider using Cyfrin Updraft, which offers comprehensive, free courses designed to help you master Solidity and advance your career in blockchain development.

Secure your protocol today

Join some of the biggest protocols and companies in creating a better internet. Our security researchers will help you throughout the whole process.
Stay on the bleeding edge of security
Carefully crafted, short smart contract security tips and news freshly delivered every week.