Overview

Solidity is a contract-oriented, high-level programming language for creating smart contracts. It was influenced by C++, Python, and JavaScript and is designed to target the Ethereum Virtual Machine (EVM) environments. Solidity is statically typed, supports inheritance, and libraries. It allows developers to create smart contracts for a wide range of use cases and applications. Key features of Solidity include:

  • Complex user-defined types
  • Inheritance and complex user-defined contracts
  • Error checking, including requirements and assertions
  • Support for libraries and user-defined functions
  • Strong security features that ensure contract integrity.

The Quai Network EVM supports Solidity versions up to 0.8.19. Using a newer version of Solidity may result in errors when deploying smart contracts.

Example Contract

The Greeter contract shown below is written with Solidity v0.8.0. Greeter serves two functions:

  • Store a greeting on-chain.
  • Return the greeting when the contract function is called.

It also contains a function for users to set a new greeting of their choice. While the Greeter contract may be simple, it showcases some of the unique functionality that smart contracts offer.

Greeter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Greeter {
    string private greeting;

    function greet() public view returns (string memory) {
        return greeting;
    }

    function setGreeting(string memory _greeting) public {
        console.log("Changing greeting from '%s' to '%s'", greeting, _greeting);
        greeting = _greeting;
    }
}

Resources

Solidity HomepageThe official Solidity homepage.
Solidity DocumentationThe official Solidity documentation.
GitHubThe Solidity GitHub Repository.
ExamplesSolidity by Example - a collection of example contracts in Solidity.