Solidity is a smart contract programming language that allows you to program decentralisation directly into every contract, ensuring transparency and security. Discover the role it plays in the Web3 ecosystem and learn how to write your first Solidity contract.
Imagine being able to create digital agreements that run themselves—no middlemen, no delays, and no need to ‘trust’ anyone. That’s exactly what smart contracts do. They’re one of the most exciting parts of blockchain technology, powering things like crypto payments, NFT trades, online voting, and even decentralised apps (DApps).
But here’s the catch: these smart contracts don’t write themselves. That’s where Solidity comes in.
Whether you’re a curious beginner, a developer interested in blockchain, or just someone who wants to understand how Web3 apps are built, this guide is for you.
By the end of this guide, you’ll have a solid understanding of:
- What Solidity is and why it’s essential for building smart contracts.
- The key role it plays in the Web3 ecosystem.
- How smart contracts function behind the scenes.
- How to write and deploy your very first Solidity contract.
What is Solidity?
Solidity is a high-level, contract-oriented programming language designed specifically for building smart contracts on the Ethereum blockchain. Created in 2014 by the Ethereum team, including co-founder Dr Gavin Wood, it was developed to bring advanced functionality to Ethereum beyond simple cryptocurrency transfers. With Solidity, developers can write self-executing contracts that run on the Ethereum Virtual Machine (EVM), enabling decentralised apps (DApps), crypto tokens, DeFi platforms, and much more.
Today, Solidity is the most widely used language in the Web3 space and is supported not just on Ethereum, but also on a growing number of EVM-compatible blockchains like Binance Smart Chain, Polygon, Avalanche, and others. It is a foundational tool for anyone looking to build in the world of decentralised technology.
Why Solidity matters in blockchain development
Solidity is more than just a programming language—it’s a core pillar of the blockchain ecosystem, especially in the world of Web3 development. It allows developers to create smart contracts that bring logic, automation, and trustless functionality to decentralised platforms. Without Solidity, many of the apps and services we associate with blockchain today wouldn’t exist in their current form. It is the engine behind many Web3 innovations like:
- DApps: Built on Ethereum and other EVM chains, DApps rely on Solidity-based smart contracts for everything from user authentication to financial transactions.
- DeFi (decentralised finance): Protocols like Uniswap, Aave, and Compound use Solidity to automate trading, lending, and yield farming—without banks or intermediaries.
- NFTs (non-fungible tokens): Solidity defines how NFTs are created, transferred, and managed through standards like ERC-721 and ERC-1155.
- DAOs (decentralised autonomous organisations): Governance rules, voting systems, and treasury management are often encoded using Solidity smart contracts.
While there are other smart contract languages, Solidity offers several practical advantages as shown in Table 1.
Basics of Solidity syntax
If you’re new to programming or have never seen Solidity before, don’t worry — it’s designed to be readable and approachable, especially if you have experience with JavaScript or C-like languages. Figure 1 will help you get comfortable with the basic syntax.

- pragma solidity ^0.8.0;
This line specifies the version of Solidity the contract is compatible with. It ensures your code won’t run on an incompatible compiler.
- contract HelloWorld { … }
This defines a smart contract named HelloWorld. Think of it as a class or program where you define your logic and data.
- string public message = “Hello, Blockchain!”;
Declares a public string variable named message. The keyword public automatically creates a getter function, allowing anyone to read the message.
- function updateMessage(string memory newMessage) public { … }
This function allows users to change the stored message. - string memory newMessage means it accepts a string stored temporarily in memory.
- public means anyone can call this function.
- message = newMessage;
Updates the contract’s state by assigning the new message to the existing message variable.
Language |
Platform |
Strengths |
Weaknesses |
Solidity |
Ethereum, EVM chains |
Familiar syntax, rich features, large ecosystem |
Prone to bugs if not written carefully |
Vyper |
Ethereum, EVM chains |
Simple, secure, easy to audit |
Fewer features, smaller community |
Rust |
Solana, Near, Polkadot |
High performance, memory safety |
Steep learning curve, not EVM-compatible |

How Solidity works (beginner-friendly explanation)
To truly grasp how Solidity works, let’s break the process down into simple steps — from writing code to running it on the Ethereum blockchain. This process involves multiple stages, and each one plays a critical role in ensuring your smart contract functions as intended.
Step 1: Write Solidity code: The journey begins when you write Solidity code. Figure 3 shows an example of a basic Solidity contract called ‘SimpleStorage’ that stores and retrieves a number. The set function stores the number in the contract, while get retrieves it.

Step 2: Compile the code with Solc (Solidity Compiler): Once you’ve written your code, it needs to be compiled into bytecode (the machine-readable code that runs on the Ethereum Virtual Machine). This is done using the Solc compiler.
This is how it works:
- Solidity (the code you wrote) is compiled into bytecode.
- The bytecode is the set of low-level instructions that can be executed by the Ethereum Virtual Machine (EVM).
You can compile your Solidity code using Remix IDE, a popular online tool for Solidity development, or use the Solc command-line compiler.
For example:
solc --bin SimpleStorage.sol
This command will output the bytecode that will be deployed to the blockchain.
Step 3: Deploy the bytecode to the Ethereum blockchain: After compiling, the bytecode is ready to be deployed to the Ethereum blockchain. This is where the Ethereum Virtual Machine (EVM) comes into play.
- Deploying means uploading your smart contract’s bytecode to the Ethereum network.
- This step is where the contract gets a permanent location on the blockchain and is ready to interact with users.

Here’s a deployment example using Remix IDE or Truffle (a development framework for Ethereum):
- Connect to a wallet (e.g., MetaMask).
- Deploy the contract by submitting the bytecode to the Ethereum network.
The contract gets an address, like 0x1234567890abcdef…, which you’ll use to interact with it later.
Step 4: Interact with the smart contract (calling functions): Now that your contract is deployed on the blockchain, users can interact with it. For example, using the set() function to store a value or the get() function to retrieve it.
Here’s an example:
- When a user calls the set() function to store a value, that function executes and updates the state of the contract.
- Calling the get() function retrieves the current stored value.
Step 5: Gas fees – the cost of executing transactions: Every time you interact with a smart contract, such as calling the set() or get() function, you’ll need to pay gas fees. Gas is the computational cost required to run operations on the Ethereum network. The cost of gas is paid in ETH, and it compensates miners or validators for processing the transaction. More complex operations (like loops or storing large amounts of data) consume more gas.
For example:
- Calling the set() function to store a number consumes gas, and the more expensive the operation, the higher the gas fees.
- get() is a read-only function (doesn’t change state), so it’s free in terms of gas when using it locally. However, reading from the blockchain still costs a small fee in practice.
When calling a function, the gas used can be calculated by the EVM based on the computational complexity. Figure 5 shows how you can estimate gas using a function call in Remix IDE.

Step 6: Executing the transaction: Once the transaction is sent (and gas is provided), the EVM validates it and executes the smart contract. If there’s enough gas, the transaction goes through, and the state of the contract is updated (e.g., the number is stored). If the transaction doesn’t have enough gas, it fails and is reverted. This is why optimising gas usage is a key part of Solidity development.
How to set up your first Solidity project
Setting up your first Solidity project involves a few key steps — from creating the development environment to writing and deploying a simple smart contract. Here is a step-by-step guide on how to do this by creating a dummy project using Solidity and Truffle (a popular framework for Ethereum-based projects).
Install Node.js: First, make sure you have Node.js installed. To check if Node.js is installed, run this command in your terminal:
node -v
Install Truffle framework: Truffle is a popular development framework for Ethereum. It simplifies the process of developing smart contracts and interacting with the blockchain.
Install Truffle globally using npm (Node Package Manager):
npm install -g truffle
Verify the installation:
truffle version
Initialise your project: Now, create a new directory for your project, and then initialise it:
mkdir MyFirstSolidityProject cd MyFirstSolidityProject truffle init
This creates the basic project structure with folders like contracts, migrations, and test.
Set up Ganache: Install Ganache for a local Ethereum blockchain. You can either download the GUI version from Ganache or use Ganache CLI with:
npm install -g ganache-cli
Now run Ganache CLI:
ganache-cli
This will give you a local blockchain running on http://127.0.0.1:8545.
Write your smart contract: In the contracts folder, create a new Solidity file called MyFirstContract.sol:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract MyFirstContract { string public message; // Constructor to initialize the message constructor() { message = “Hello, World!”; } // Function to set a new message function setMessage(string memory newMessage) public { message = newMessage; } }
Create a migration script: In the migrations folder, create a new migration file named 2_deploy_contracts.js to deploy the contract:
const MyFirstContract = artifacts.require(“MyFirstContract”); module.exports = function (deployer) { deployer.deploy(MyFirstContract); };
Configure Truffle to use Ganache: In the truffle-config.js file, configure the development network to use Ganache:
Module.exports = { networks: { development: { host: “127.0.0.1”, // Localhost port: 8545, // Ganache default port Network_id: “*”, // Match any network id }, }, compilers: { solc: { version: “0.8.0”, // Solidity version }, }, };
Compile your contract: Now compile your smart contract to generate the necessary artifacts:
truffle compile
Deploy to Ganache: Deploy the contract to your local Ganache blockchain with:
truffle migrate --network development
This deploys the contract to the blockchain.
Interact with the contract: Open the Truffle console to interact with the deployed contract:
truffle console --network development
In the console, get the deployed contract instance:
let instance = await MyFirstContract.deployed();
Check the initial message:
let message = await instance.message(); console.log(message); // “Hello, World!”
Change the message:
await instance.setMessage(“New Message!”);
Check the updated message:
message = await instance.message(); console.log(message); // “New Message!”
Test your contract (optional): To ensure your contract works as expected, write tests in the test folder. Create a file myFirstContractTest.js:
const MyFirstContract = artifacts.require(“MyFirstContract”); contract (“MyFirstContract”, () => { it(“should store and update message”, async () => { const instance = await MyFirstContract.deployed(); let message = await instance.message(); assert.equal(message, “Hello, World!”, “Initial message is incorrect”); await instance.setMessage(“Test Message”); message = await instance.message(); assert.equal(message, “Test Message”, “Message was not updated”); }); });
Run the tests:
truffle test
Where to practice Solidity
You’ve learned the basics, written your first smart contract, and even deployed it locally—what’s next? Like any skill, mastering Solidity takes consistent practice. Luckily, there are several beginner-friendly platforms where you can experiment, test, and even play games to sharpen your smart contract skills.
Here are some top platforms to help you level up.
Remix IDE: Remix is a web-based Solidity development environment. It requires no setup, making it perfect for quick experiments, learning, and testing your code in the browser. It supports compiling, deploying, and debugging smart contracts all in one place.
- No installation required
- Built-in Solidity compiler and deployer
- Ideal for both beginners and pros
CryptoZombies: CryptoZombies is a fun, gamified platform where you learn Solidity by building your own zombie-themed game. Each lesson introduces new concepts in an engaging and visual way.
- Great for complete beginners
- Teaches Solidity through game-building
- Step-by-step, interactive format
EthFiddle: EthFiddle is like a ‘JSFiddle’ for Solidity. It lets you write and share Solidity code snippets with others. You can quickly test contracts and collaborate on ideas without leaving the browser.
- Lightweight and simple
- Easy sharing of contract examples
- Good for bite-sized experimentation
Alchemy and Infura (for testnet deployment): When you’re ready to go beyond local development, tools like Alchemy and Infura allow you to connect to Ethereum testnets like Goerli or Sepolia. These platforms act as blockchain infrastructure providers and help you interact with real networks—without spending real ETH.
- Deploy contracts to live testnets
- Use test ETH for experimenting
- Helpful for simulating mainnet deployment conditions
Final thoughts
Congrats! You’ve learned the basics of Solidity and how it powers smart contracts in the blockchain world. Whether you’re building DApps, exploring DeFi, or creating NFTs, Solidity is at the heart of many Web3 innovations.
But don’t stop here—practice is key. Start writing your own smart contracts, deploy them locally, and experiment with platforms like Remix IDE, CryptoZombies, and Alchemy. The more you build, the better you’ll get.
Web3 is full of possibilities, and with Solidity, you’re ready to create your own. So, take the leap and start building your part of the blockchain revolution today!