Solidity Cheat Sheet - Every Pattern You Need (2026)
DevTools StoreSolidity Cheat Sheet - Every Pattern You Need (2026)
Complete Solidity reference. Types, functions, modifiers, events, security.
Web3 dev tools + 7 products for $1+ (ETH): https://rentry.co/dev-tools-pay-what-you-want
Data Types
uint256, int256, address, string, bytes32, bool
Mapping: mapping(address => uint256) public balances;
Array: uint256[] public items;
Struct: struct User { address wallet; uint256 balance; bool active; }
Functions
public view - Read, no gas
public pure - No state read
public payable - Accepts ETH
external - Only callable from outside
internal - Contract + children only
private - This contract only
Modifiers
modifier onlyOwner() { require(msg.sender == owner); _; }
modifier costs(uint price) { require(msg.value >= price); _; }
Events
event Transfer(address indexed from, address indexed to, uint256 amount);
emit Transfer(msg.sender, to, amount);
Security
Checks-Effects-Interactions: Check first, update state, then interact
Reentrancy: bool locked; modifier noReentrant { require(!locked); locked=true; _; locked=false; }
Safe transfer: (bool ok,) = to.call{value: amount}(""); require(ok);
ERC20 Pattern
mapping(address => uint256) public balanceOf;
function transfer(address to, uint amount) public { require(balanceOf[msg.sender] >= amount); balanceOf[msg.sender] -= amount; balanceOf[to] += amount; }
Deploy with Foundry
forge init my-contract && forge build && forge test
forge create src/Contract.sol:MyContract --rpc-url $RPC --private-key $KEY
---
More Web3 tools: https://rentry.co/pgib9826