Solidity | Sheetly Cheat Sheet

Last Updated: November 21, 2025

Solidity

Smart contract programming language

Basic Contract

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimpleStorage {
    uint256 private storedData;
    
    event ValueChanged(uint256 newValue);
    
    function set(uint256 x) public {
        storedData = x;
        emit ValueChanged(x);
    }
    
    function get() public view returns (uint256) {
        return storedData;
    }
}

Data Types

Item Description
uint Unsigned integer (uint256)
int Signed integer
bool Boolean (true/false)
address Ethereum address
string Text string
bytes Fixed/dynamic byte array
mapping Key-value store

Function Modifiers

contract Owned {
    address public owner;
    
    constructor() {
        owner = msg.sender;
    }
    
    modifier onlyOwner() {
        require(msg.sender == owner, "Not owner");
        _;
    }
    
    function changeOwner(address newOwner) public onlyOwner {
        owner = newOwner;
    }
}

Common Patterns

  • require(): Input validation and error handling
  • payable: Functions that receive Ether
  • msg.sender: Address calling the function
  • msg.value: Amount of Ether sent
  • address.transfer(): Send Ether safely
  • Events: Log important state changes

💡 Pro Tips

Quick Reference

Write secure smart contracts for Ethereum

← Back to Data Science & ML | Browse all categories | View all cheat sheets