Introduction to Solidity
Get an overview of Solidity's syntax, structure, and basic contract declaration, including pragma and contract keywords.
Introduction to Solidity is a free Web3 & DApp Development Fundamentals lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Web3 & DApp Development Fundamentals learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Meet Solidity: Language of Smart Contracts
Welcome to Solidity! It's the primary language for writing smart contracts on blockchain platforms like Ethereum.
Think of smart contracts as self-executing agreements stored on a blockchain. Learning Solidity opens the door to building decentralized applications (DApps).
Why Solidity Matters
Solidity is a high-level, object-oriented language. It's specifically designed to implement business logic for DApps.
It enables you to create digital tokens, build decentralized finance (DeFi) protocols, and manage digital assets securely on a blockchain.
Your First Solidity File
Every Solidity smart contract lives in a file ending with the .sol extension.
- Just like a
.jsfile for JavaScript. - Or a
.pyfile for Python. - The first line of a Solidity file often defines the compiler version to be used.
The Pragma Directive
The pragma directive is crucial. It tells the Solidity compiler which version to use for your contract.
For example, pragma solidity ^0.8.0; means "use any compiler version from 0.8.0 up to, but not including, 0.9.0."
This ensures your contract compiles predictably and avoids unexpected behavior from future compiler changes.
Declaring a Contract
In Solidity, the fundamental building block for your smart contract is the contract keyword.
- It's similar to a "class" in object-oriented programming languages.
- Your entire smart contract's logic, including variables and functions, will live inside a
contractblock.
Our First Basic Contract
Let's put pragma and contract together. This is the most basic, yet complete, Solidity contract you can write.
It doesn't do much yet, but it's ready to be compiled and deployed!
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract MyFirstContract {
// This contract is currently empty!
}Comments in Solidity
Comments help explain your code to others and your future self. They are ignored by the compiler.
- Single-line comments start with
//. - Multi-line comments are enclosed by
/*and*/. - The
SPDX-License-Identifieris a special comment used to specify the contract's license.
Contract Name & Structure
Contract names usually start with an uppercase letter, following common programming conventions (e.g., MyFirstContract).
The code inside the curly braces {} defines the contract's logic. This is where you'll add state variables, functions, and events as you learn more.
Quick Check: Pragma Purpose
The pragma solidity ^0.8.0; line is essential for smart contract development. What is its primary role?
Recap: Your Solidity Journey Begins!
You've learned the very basics of Solidity!
- We covered the
.solfile extension. - The critical
pragmadirective for compiler versions. - The fundamental
contractkeyword. - How to add comments for code clarity.
Next, we'll dive deeper into variables and data types!
Frequently asked questions
Is the “Introduction to Solidity” lesson free?
Yes — the full text of “Introduction to Solidity” is free to read here on the web, and the Web3 & DApp Development Fundamentals course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Web3 & DApp Development Fundamentals course, upgrade to CoddyKit PRO.
What will I learn in “Introduction to Solidity”?
Get an overview of Solidity's syntax, structure, and basic contract declaration, including pragma and contract keywords. You practise Web3 & DApp Development Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Web3 & DApp Development Fundamentals?
No prior experience is required. Web3 & DApp Development Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Introduction to Solidity” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Web3 & DApp Development Fundamentals lesson?
Yes. Every Web3 & DApp Development Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Introduction to Solidity
- Variables & Data Types
- Functions & Control Structures