Your First Solidity Contract
Write and compile a simple 'Hello World' smart contract using Remix IDE, gaining hands-on experience with Solidity syntax.
Your First Solidity Contract is a free Blockchain Smart Contracts with Solidity lesson on CoddyKit — lesson 3 of 4. 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 Blockchain Smart Contracts with Solidity learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Your First Smart Contract!
Time to write your first smart contract! We'll build a simple Hello World in Solidity using the browser-based Remix IDE - no setup needed.
Meet Remix IDE
Remix IDE lets you write, compile, debug, and deploy Solidity contracts right in your browser. It's perfect for learning and quick prototyping.
Solidity Version Pragma
Every Solidity file opens with a pragma that pins the compiler version. The code below means versions 0.8.0 up to (but not including) 0.9.0 are allowed.
pragma solidity ^0.8.0;Defining Your Contract
Solidity code lives inside a contract, much like a class in OOP. You declare it with the contract keyword, a name, and curly braces, as shown.
contract MyFirstContract {
// Your contract's code goes here
}Adding a State Variable
A state variable is stored permanently on chain and defines your contract's state. Here we add a string called greeting; public makes it readable by anyone.
contract MyFirstContract {
string public greeting;
}The Constructor Function
The constructor runs exactly once, at deployment, to initialize state. Here it sets greeting to "Hello CoddyKit!" the moment the contract goes live.
contract MyFirstContract {
string public greeting;
constructor() {
greeting = "Hello CoddyKit!";
}
}Writing a View Function
A view function reads contract state without changing it. This getGreeting is public and returns a string from memory, as shown below.
contract MyFirstContract {
string public greeting;
constructor() {
greeting = "Hello CoddyKit!";
}
function getGreeting() public view returns (string memory) {
return greeting;
}
}Our Full 'Hello World' Contract
Here's the full Hello World contract. Paste it into Remix, compile, deploy to a test chain, then call getGreeting() to see it work.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleGreeting {
string public greeting;
constructor() {
greeting = "Hello CoddyKit!";
}
function getGreeting() public view returns (string memory) {
return greeting;
}
}Compiling Your Contract
Before deploying, a contract must be compiled - turning your Solidity into EVM bytecode. Remix has a built-in compiler with a handy Auto compile option.
Quick Check: Contract Structure
Which part of a Solidity smart contract specifies the minimum compatible compiler version?
Recap: Your First Contract
Recap: you built a Solidity contract with a pragma, a contract block, a state variable, a constructor, and a view function - all in Remix. Nice work!
Frequently asked questions
Is the “Your First Solidity Contract” lesson free?
Yes — the full text of “Your First Solidity Contract” is free to read here on the web, and the Blockchain Smart Contracts with Solidity course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Blockchain Smart Contracts with Solidity course, upgrade to CoddyKit PRO.
What will I learn in “Your First Solidity Contract”?
Write and compile a simple 'Hello World' smart contract using Remix IDE, gaining hands-on experience with Solidity syntax. You practise Blockchain Smart Contracts with Solidity 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 Blockchain Smart Contracts with Solidity?
No prior experience is required. Blockchain Smart Contracts with Solidity on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Your First Solidity Contract” 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 Blockchain Smart Contracts with Solidity lesson?
Yes. Every Blockchain Smart Contracts with Solidity 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
- What is Blockchain Technology?
- Ethereum Basics and EVM
- Your First Solidity Contract
- Wallets, Keys, and Transactions