Trusted Certifications for 10 Years | Flat 25% OFF | Code: GROWTH
Blockchain Council
solidity5 min read

Learn Solidity: Basics of Solidity By Example

Suyash RaizadaSuyash Raizada
Updated Apr 30, 2026
Learn Solidity - Build Decentralized Application in Ethereum

Solidity is the primary programming language used to write smart contracts on Ethereum and other EVM-compatible blockchains. While its syntax is similar to JavaScript, Solidity introduces unique concepts such as gas costs, immutability, and blockchain-based execution.

This guide explains Solidity basics using a modern example contract. It updates outdated concepts, aligns with Solidity 0.8.x standards, and provides a clear understanding of how smart contracts work in practice. Start learning Solidity with real-world examples including variables, functions, and contract deployment by building expertise through a Certified Blockchain Expert, testing logic using a Python certification, and showcasing your projects via a Digital marketing course.

Certified Artificial Intelligence Expert Ad Strip

What Is Solidity?

Solidity is a statically typed, contract-oriented programming language used to develop decentralized applications (DApps). It runs on the Ethereum Virtual Machine (EVM), enabling developers to create secure and automated programs.

Smart contracts written in Solidity are immutable once deployed, meaning they cannot be easily changed. This makes correctness and security critical.

A Simple Solidity Contract Example

Below is a modern version of a basic token-like contract:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

contract SimpleToken {

   address public owner;

   uint256 public totalSupply;

   mapping(address => uint256) public balances;

   event Transfer(address indexed from, address indexed to, uint256 value);

   event Mint(address indexed to, uint256 value);

   constructor(uint256 initialSupply) {

       owner = msg.sender;

       totalSupply = initialSupply;

       balances[msg.sender] = initialSupply;

   }

   function transfer(address to, uint256 amount) public {

       require(balances[msg.sender] >= amount, "Insufficient balance");

       balances[msg.sender] -= amount;

       balances[to] += amount;

       emit Transfer(msg.sender, to, amount);

   }

   function mint(address to, uint256 amount) public {

       require(msg.sender == owner, "Only owner can mint");

       totalSupply += amount;

       balances[to] += amount;

       emit Mint(to, amount);

   }

}

This contract demonstrates core Solidity concepts used in real-world development.

Contract Step by Step

Pragma Directive

pragma solidity ^0.8.20;

This specifies the compiler version. Modern Solidity uses version 0.8.x, which includes built-in overflow checks and improved safety.

Contract Declaration

contract SimpleToken

A contract is similar to a class in object-oriented programming. It defines state variables and functions.

State Variables

address public owner;

uint256 public totalSupply;

State variables store data on the blockchain. Declaring them as public automatically creates getter functions.

Mapping

mapping(address => uint256) public balances;

A mapping stores key-value pairs. Here, it tracks how many tokens each address owns.

Events

event Transfer(address indexed from, address indexed to, uint256 value);

event Mint(address indexed to, uint256 value);

Events allow contracts to log important actions. External applications can listen to these logs.

Constructor

constructor(uint256 initialSupply)

The constructor runs once when the contract is deployed. It initializes the owner and assigns the initial token supply.

Transfer Function

function transfer(address to, uint256 amount)

This function allows users to send tokens. It checks balances, updates them, and emits an event.

Mint Function

function mint(address to, uint256 amount)

This function creates new tokens. Only the owner can call it, ensuring controlled supply.

Key Concepts in Solidity

msg.sender

Represents the address that calls a function. It is used for authentication and access control.

require Statements

Used to validate conditions. If the condition fails, the transaction is reverted.

Gas and Execution

Every operation costs gas. Efficient code reduces transaction costs.

Immutability

Once deployed, smart contracts cannot be modified. Updates require deploying new contracts.

Differences Between Old and Modern Solidity

Older Solidity versions (like 0.4.x) required manual handling of overflows and used deprecated functions such as selfdestruct without safeguards.

Modern Solidity (0.8.x):

  • Includes built-in overflow protection

  • Improves error handling

  • Provides better security features

  • Encourages safer coding patterns

Developers should always use the latest stable version.

Best Practices for Writing Solidity Contracts

  • Use the latest compiler version

  • Follow security guidelines and audit your code

  • Use libraries like OpenZeppelin

  • Avoid unnecessary complexity

  • Write comprehensive tests

These practices reduce vulnerabilities and improve reliability.

Common Mistakes Beginners Make

  • Ignoring gas optimization

  • Not validating inputs properly

  • Using outdated Solidity syntax

  • Failing to test edge cases

  • Mismanaging access control

Avoiding these mistakes is essential for building secure applications.

Tools for Solidity Development

  • Remix IDE for quick testing

  • Hardhat for development and deployment

  • Foundry for fast testing and scripting

  • Ethers.js for frontend integration

Using these tools improves efficiency and workflow.

What to Build After Learning Basics

Once you understand Solidity basics, try building:

  • ERC-20 or ERC-721 tokens

  • Decentralized voting systems

  • Crowdfunding platforms

  • DAO governance contracts

Practical projects help reinforce concepts.

The Future of Solidity Development

Solidity continues to evolve alongside Ethereum. Trends include:

  • Layer 2 deployment for lower costs

  • Account abstraction for better user experience

  • Integration with zero-knowledge proofs

  • Increased focus on security and audits

Developers who stay updated will remain competitive in the Web3 ecosystem.

Build your first smart contracts and understand Solidity fundamentals step-by-step by mastering blockchain development through a Certified Blockchain Expert, integrating applications using a Node JS Course, and promoting your developer journey using an AI powered marketing course.

Frequently Asked Questions (FAQs)

1. What is Solidity used for?

Solidity is used to write smart contracts for Ethereum and other EVM-compatible blockchains. These contracts power decentralized applications.

2. Is Solidity similar to JavaScript?

Yes, its syntax is similar, but Solidity includes blockchain-specific features like gas costs and immutability.

3. What is a smart contract?

A smart contract is a self-executing program stored on a blockchain. It runs automatically when conditions are met.

4. What is pragma in Solidity?

Pragma specifies the compiler version required to compile the contract.

5. What is a mapping in Solidity?

A mapping is a data structure that stores key-value pairs, commonly used for balances or ownership.

6. What are events in Solidity?

Events log data on the blockchain, allowing external applications to track contract activity.

7. What is msg.sender?

It is the address of the account that calls a function.

8. What does it require to do in Solidity?

Require checks conditions and reverts the transaction if the condition is not met.

9. What is gas in Ethereum?

Gas is the fee required to execute transactions or smart contract operations.

10. What is a constructor in Solidity?

A constructor is a special function that runs once during contract deployment.

11. What is the latest Solidity version?

As of 2026, Solidity 0.8.x is widely used and recommended.

12. Can smart contracts be modified?

No, once deployed, they are immutable. Updates require deploying a new contract.

13. What is OpenZeppelin?

OpenZeppelin provides secure and reusable smart contract libraries.

14. What is ERC-20?

ERC-20 is a standard for creating fungible tokens on Ethereum.

15. What is ERC-721?

ERC-721 is a standard for creating non-fungible tokens (NFTs).

16. How do I test Solidity contracts?

You can use tools like Hardhat or Foundry to write automated tests.

17. What is Remix IDE?

Remix is a browser-based tool for writing, testing, and deploying smart contracts.

18. What are common Solidity vulnerabilities?

Common issues include reentrancy, overflow bugs, and improper access control.

19. Is Solidity hard to learn?

It is relatively easy for developers with programming experience, but mastering security takes time.

20. What should I build after learning Solidity?

Start with tokens, voting systems, or crowdfunding apps to gain practical experience.


Related Articles

View All

Trending Articles

View All