Halloween at the Portal. The Hollow, a haunted cipher maze, is free to play until 2 November. Enter The Hollow

Smart Contract Puzzle

Interactive smart contract simulator and Solidity learning tool

How to Learn Smart Contracts:

  1. Select a Contract: Choose from Counter, Token, Voting, or Auction
  2. Read the Code: Study the Solidity contract structure
  3. View State: See current contract state variables
  4. Execute Functions: Call functions with different parameters
  5. Track Changes: Watch state update as functions execute
  6. Monitor Gas: See cumulative gas costs for operations

📋 Select a Smart Contract

📜 Execution History

🧠 Understanding Smart Contracts

Smart contracts are self-executing programs that run on the blockchain. They automatically execute when conditions are met, with no intermediary needed. In this tool, you'll learn how contracts store state, execute functions, and consume gas.

💾 State Variables

Data stored permanently on-chain. Changing state costs gas and requires a transaction.

⚙️ Functions

CODE that executes when called. Some change state (cost gas), others just read (view functions).

🔐 Visibility

Public functions can be called by anyone. Private functions only work internally.

💨 Gas Cost

Every operation costs gas. More complex operations = higher cost. Total gas = operations × gas price.

📚 Contract Types in This Tool

1. Counter Contract

The simplest contract! Tracks a number and lets you increment/decrement it. Perfect for learning basics.

  • increment(): Add 1 to counter (21,000 gas)
  • decrement(): Subtract 1 (with check: can't go negative)
  • getCount(): View current count (view function, no gas)
  • reset(): Set counter to 0

2. Token Contract

Simulates ERC20 token transfers. Teaches how token balances work across addresses.

  • transfer(): Send tokens to another address (35,000 gas)
  • balanceOf(): Check any address's balance (view function)
  • Requires: Sender has enough tokens

3. Voting Contract

Democratic decision-making on blockchain. Shows struct usage and voting logic.

  • createProposal(): Create new voting option (45,000 gas)
  • vote(): Cast your vote (50,000 gas)
  • getVotes(): Check vote count for proposal (view function)
  • Prevents: Double voting

4. Auction Contract

Competitive bidding system. Shows require statements and value validation.

  • bid(): Place a bid (55,000 gas)
  • endAuction(): Close bidding (21,000 gas)
  • getHighestBid(): View winning bid (view function)
  • Requires: Bid > current highest

⛽ Understanding Gas

Gas measures computational cost. Every EVM operation costs gas. The simulator shows approximate gas for each function:

  • Simple operations: 100-1,000 gas (reading, comparisons)
  • State changes: 5,000-50,000 gas (writing to storage)
  • Complex logic: 20,000-100,000+ gas (loops, calculations)

💡 Real Cost: Gas Cost (wei) = Total Gas × Gas Price (gwei)

🔍 Function Types

  • State-Modifying Functions: Change contract state, cost gas, require transactions
  • View Functions: Read-only, no gas cost, instant results

In this tool, VIEW functions show with blue background | STATE functions show with green background.

Part of the Matrix Portal Crypto Tools Collection

Educational purposes only • All operations performed client-side

Privacy Policy • Terms of Service