Smart Contracts and the Ethereum Virtual Machine
A smart contract is a program stored on the blockchain that runs automatically when pre-defined conditions are met. Nick Szabo coined the concept in 1994; Ethereum made it practical in 2015.
The Classic Analogy
A vending machine is a primitive smart contract: you insert money (condition met), the machine dispenses the product (automatic execution), no human cashier involved (trustless). Smart contracts extend this to arbitrary logic — loans, voting, token issuance, insurance payouts, auctions.
How Ethereum Smart Contracts Work
- A developer writes a contract in Solidity (or Vyper)
- The code is compiled to EVM bytecode
- The contract is deployed to Ethereum — it gets a permanent address on the blockchain
- Anyone can call its functions by sending a transaction. The EVM executes the code deterministically across all nodes
- Execution costs gas — ETH paid to validators for computation
A Simple Solidity Example
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleStorage {
uint256 private value;
function set(uint256 _value) public {
value = _value;
}
function get() public view returns (uint256) {
return value;
}
}
Once deployed, anyone can call set() or get(). The state lives on-chain forever. No server to hack, no company to shut it down.
Gas and Transaction Costs
Every EVM operation has a gas cost. Complex contracts cost more gas. Gas price fluctuates with network demand. During high-congestion periods (like NFT launches), gas fees can exceed the value being transferred — this is a major usability problem Ethereum is addressing with Layer 2 solutions.
Smart Contract Risks
- Code is law — bugs cannot be patched after deployment without migration to a new contract
- Re-entrancy attacks — the DAO hack (2016) drained $60M by exploiting recursive calls
- Oracle problem — contracts cannot safely access off-chain data without a trusted oracle (Chainlink)
- Integer overflow — Solidity ≥0.8 has built-in overflow protection; older contracts did not