Solidity Cheat Sheet
Essential Solidity syntax for Ethereum smart contracts, covering state variables, functions, modifiers, and events.
2 PagesIntermediateMar 25, 2026
Hello World Contract
A minimal contract with a public state variable.
solidity
// SPDX-License-Identifier: MITpragma solidity ^0.8.20;contract HelloWorld { string public greeting = "Hello, World!"; function setGreeting(string memory _greeting) public { greeting = _greeting; }}
Contract Structure
State variables, a mapping, and a constructor.
solidity
contract Token { string public name; uint256 public totalSupply; address public owner; mapping(address => uint256) public balanceOf; constructor(string memory _name, uint256 _supply) { name = _name; totalSupply = _supply; owner = msg.sender; balanceOf[msg.sender] = _supply; }}
Functions & Modifiers
Visibility, mutability, and reusable checks.
- public- Callable externally and internally; auto-generates a getter for state vars
- private- Callable only within the defining contract
- view- Reads state but doesn't modify it
- pure- Doesn't read or modify contract state
- payable- Marks a function as able to receive Ether
- modifier onlyOwner() { require(msg.sender == owner, "not owner"); _; }- Reusable precondition wrapper
Data Types
Common Solidity value and reference types.
- uint256- Unsigned 256-bit integer (the default uint)
- address- 20-byte Ethereum account/contract address
- mapping(address => uint256)- Hash-map-like key/value storage
- bytes32- Fixed-size 32-byte value
- bool- true/false
- string memory- Dynamically-sized UTF-8 string, memory-allocated
Events
Emitting logs for off-chain listeners.
solidity
event Transfer(address indexed from, address indexed to, uint256 value);function transfer(address to, uint256 amount) public returns (bool) { require(balanceOf[msg.sender] >= amount, "insufficient balance"); balanceOf[msg.sender] -= amount; balanceOf[to] += amount; emit Transfer(msg.sender, to, amount); return true;}
Pro Tip
Always use the checks-effects-interactions pattern — update state before making external calls — to prevent reentrancy attacks.
Was this cheat sheet helpful?
Explore Topics
#Solidity#SolidityCheatSheet#Programming#Intermediate#HelloWorldContract#ContractStructure#FunctionsModifiers#DataTypes#Functions#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance