Learning Objectives – after this chapter you will be able to:
- Explain what Solidity is, where it runs and what it is used for.
- Describe how Solidity code becomes bytecode and an ABI.
- Use Remix IDE to write, compile, deploy and test a contract.
Solidity
- Solidity is an object-oriented (contract-oriented), high-level programming language for writing smart contracts – programs that control the behaviour of accounts within the Ethereum state.
- It is designed to target the Ethereum Virtual Machine (EVM), so the same code also runs on other EVM-compatible blockchains.
- Its syntax was influenced by C++, Python and JavaScript.
- Solidity is statically typed and supports inheritance, libraries and complex user-defined types (structs, enums).
- With Solidity you can build contracts for voting, crowdfunding, auctions, tokens, multi-signature wallets and much more – several of these are built as projects in this course.
A short history
- Solidity was proposed in August 2014 by Gavin Wood and was then developed by the Ethereum project’s Solidity team, initially led by Christian Reitwiessner.
- Today it is the most widely used language for Ethereum smart contracts. The language is still evolving; this course uses the 0.8.x seriesexamples compiled with solc 0.8.26.
From Source Code to a Deployed Contract
1. Write
.sol source file2. Compilesolc produces bytecode + ABI
3. DeployA transaction stores the bytecode; the contract gets an address
4. InteractWallets / Web3.js call functions using the ABI
- Bytecode – the low-level EVM instructions stored on the blockchain.
- ABI (Application Binary Interface) – a JSON description of the contract’s functions and events that front ends (e.g. Web3.js) use to call it.
Remix IDE
- Remix IDE is a free, browser-based development environment used for the whole smart-contract workflow – writing, compiling, deploying, testing and debugging.
- It needs no installation, gives a fast development cycle and has many plugins with simple graphical interfaces. It is also available as a desktop application and as an editor extension.
- Remix Online IDE: https://remix.ethereum.org (modern browsers such as Chrome, Firefox and Brave are supported).
Main panels of Remix
| Panel | Use |
|---|---|
| File Explorer | Create folders and .sol files (Remix starts with a contracts/ folder). |
| Solidity Compiler | Choose the compiler version and compile; shows errors, warnings, ABI and bytecode. |
| Deploy & Run Transactions | Choose an environment, select an account, deploy the contract and call its functions. |
| Terminal | Shows transaction details, logs and gas used. |
| Debugger | Step through a transaction opcode by opcode. |
Environments in “Deploy & Run”
- Remix VM – an in-browser test blockchain with pre-funded test accounts (best for learning).
- Injected Provider – uses a browser wallet such as MetaMask to deploy to a testnet or mainnet.
- External / custom HTTP provider – connects to a local node such as a development blockchain.
Your First Contract in Remix
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract HelloWorld {
string public message = "Hello, Solidity!";
function setMessage(string calldata newMessage) public {
message = newMessage; // writes to the blockchain: needs a transaction
}
}
- Create
contracts/HelloWorld.soland paste the code. - Open Solidity Compiler, select a 0.8.x version and click Compile.
- Open Deploy & Run, keep Remix VM, click Deploy.
- Under Deployed Contracts click message (a free read) and then call setMessage (a transaction that costs test gas).
Key Takeaways
- Solidity is a statically typed, contract-oriented language for the EVM.
- Compiling produces bytecode (for the chain) and an ABI (for applications).
- Remix lets you write, compile, deploy and test contracts directly in the browser.
Download | Print E-Notes
The PDF E-Notes are the earlier printable version of this chapter. The notes on this page are the latest, revised version.
Video : Solidity and Remix IDE Setup
Question / Answer (15 questions)
Answer : Solidity is a statically typed, contract-oriented, high-level programming language for writing smart contracts that run on the Ethereum Virtual Machine (EVM) and other EVM-compatible blockchains.
Answer : Solidity’s design was influenced mainly by C++, Python and JavaScript.
Answer : Solidity was proposed by Gavin Wood in August 2014. It was then developed by the Ethereum project’s Solidity team, initially led by Christian Reitwiessner.
Answer : The EVM is the runtime environment present on every Ethereum node that executes contract bytecode deterministically, so all nodes reach the same result.
Answer : Bytecode, which is deployed and executed by the EVM, and the ABI (Application Binary Interface), a JSON description of the contract’s functions and events used by front ends and other tools to call the contract.
Answer : Remix is a browser-based IDE for writing, compiling, deploying, testing and debugging smart contracts. It needs no installation, provides a built-in test blockchain (Remix VM) and shows results immediately, which makes it ideal for beginners.
Answer : File Explorer, Solidity Compiler, Deploy & Run Transactions, Terminal and Debugger (plus optional plugins).
Answer : Remix VM is an in-browser simulated blockchain with pre-funded test accounts. Transactions are instant and free of real cost, so it is used for learning and quick testing.
Answer : It connects Remix to a browser wallet such as MetaMask so contracts can be deployed to and used on a real network such as a testnet or mainnet, with the wallet signing the transactions.
Answer : setMessage changes contract storage, so it must be sent as a transaction that every node executes and records. Reading a public variable only queries a node locally (a call) and does not change state.
Answer : A deployment transaction containing the creation bytecode is executed; the constructor runs, the runtime bytecode is stored on the blockchain and the contract receives its own address.
Answer : No. Solidity targets the EVM, so it is also used on other EVM-compatible blockchains and Layer-2 networks.
Answer : Voting systems, crowdfunding platforms, auctions, tokens (ERC-20/721), multi-signature wallets and lotteries are common examples.
Answer : Different compiler versions support different language features and may behave differently. The version must satisfy the file’s pragma, otherwise compilation fails.
Answer : The 0.8.x series; the examples were compiled with solc 0.8.26. Version 0.8 added important safety features such as automatic overflow checks.
MCQ Test : Check Your Understanding (5 questions)
Select an option and press Check Answer, or answer all questions and press Submit Test to see your score. Each answer comes with an explanation.
Bibliography/References
The notes, questions and MCQs on this page are original explanations written for this course. The works listed below were consulted and are cited for attribution and further reading. Product names, logos and trademarks belong to their respective owners. Short quotations, where used, are marked and attributed.
- Solidity Team. (n.d.). Solidity Documentation (latest). https://docs.soliditylang.org/en/latest/
- Solidity Team. (n.d.). Introduction to Smart Contracts. Solidity Documentation. https://docs.soliditylang.org/en/latest/introduction-to-smart-contracts.html
- Remix Project. (n.d.). Remix IDE Documentation. https://remix-ide.readthedocs.io/en/latest/
- Remix Project. (n.d.). Remix – Ethereum IDE (online). https://remix.ethereum.org
- ethereum.org. (n.d.). Smart contract languages. Ethereum Developer Documentation. https://ethereum.org/en/developers/docs/smart-contracts/languages/
- ethereum.org. (n.d.). Ethereum Virtual Machine (EVM). Ethereum Developer Documentation. https://ethereum.org/en/developers/docs/evm/
- Wikipedia contributors. (n.d.). Solidity. Wikipedia, The Free Encyclopedia. https://en.wikipedia.org/wiki/Solidity
- Modi, R. (2018). Solidity Programming Essentials: A beginner’s guide to build smart contracts for Ethereum and blockchain. Packt Publishing. ISBN 978-1-78883-138-3.