Solidity · Beginner
What is a smart contract? A plain-English explanation with a real example
A smart contract is a program on a blockchain that runs exactly as written when someone sends it a transaction. Here is how they work, what they are used for, and a real ten-line example you can deploy.
A smart contract is a small program that lives on a blockchain. Anyone can send it a transaction; it runs the matching function, updates its own stored data, and possibly moves tokens. No company operates it, nobody can switch it off, and everyone can read its code and its state.
The vending machine analogy, and where it breaks
The classic description is a vending machine: put in a coin, press a button, get a snack, no shopkeeper. That captures the automation. It misses the second property, which is that the machine's rules and its entire transaction history are public and verifiable by anyone. A smart contract is a vending machine with glass walls and a ledger bolted to the side.
How they actually work
- A developer writes the contract in a language such as Solidity and compiles it to bytecode.
- They deploy it: a transaction that stores the bytecode at a new address on the chain.
- Users send transactions to that address. Each carries a function selector and arguments.
- Every node on the network runs the function and agrees on the resulting state.
- The contract's storage is updated, events are emitted, and the transaction is included in a block.
A real example
solidity// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract Guestbook {
mapping(address => string) public message;
event Signed(address indexed who, string message);
function sign(string calldata text) external {
message[msg.sender] = text;
emit Signed(msg.sender, text);
}
}Anyone can call sign. Each address gets one message slot, which only that address can change. Reading message(addr) is free; writing costs gas. That is a complete, deployable smart contract. You can paste it into monsmith.com/studio, compile it, and put it on Monad testnet in about two minutes.
What they are used for
- Tokens: ERC-20 currencies and stablecoins, ERC-721 NFTs.
- Decentralised finance: exchanges, lending, derivatives, all as contracts.
- Games and social apps where items and identity are owned by users.
- Escrow, payroll, vesting, and other agreements that pay out on conditions.
- Governance: proposals and votes recorded and executed on-chain.
What makes them hard
Deployed code cannot be edited. A bug in a normal app gets patched; a bug in a contract that holds funds gets exploited. That is why the discipline around smart contracts is heavier than around ordinary software: audits, formal verification, extensive testnet use, and tooling that finds problems before deployment. It is also why Monsmith runs a security audit on every contract before it lets you press Deploy.
Frequently asked questions
- Are smart contracts legal contracts?
- Not by default. A smart contract is code that executes automatically. Whether it also constitutes a legally binding agreement depends on jurisdiction and on what the parties agreed off-chain.
- What language are smart contracts written in?
- On Ethereum, Monad, and other EVM chains, mostly Solidity, with Vyper as an alternative. Other ecosystems use Rust (Solana), Move (Aptos, Sui), or others.
- Can a smart contract be changed after deployment?
- The deployed bytecode cannot. Developers use proxy patterns to point an address at new logic, but that must be designed in before deployment.
Try it in Monsmith
Free, in the browser, no account. Compile, audit, profile, and deploy to Monad.
Open the studio