Smart Contracts
Definition
A smart contract is a program stored on a blockchain that automatically executes when predetermined conditions are met. It encodes the rules of an agreement and enforces them programmatically — no intermediary (bank, lawyer, notary) is needed.
Core Ideas
Properties
- Deterministic — given the same inputs and state, always produces the same output
- Immutable — once deployed, code cannot be changed (upgradeable patterns exist as workarounds)
- Transparent — code is publicly visible on-chain
- Trustless — execution is enforced by the network, not a central party
- Permissionless — anyone can deploy or interact with a contract
Ethereum & Solidity
Ethereum is the primary platform for smart contract development in the source notes.
Solidity basics:
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;
}
}Key concepts:
addresstype for Ethereum accounts and contractsmappingfor key-value storageeventfor emitting logs (cheaper than storage)modifierfor access controlpayablefor receiving ETH
Token Standards
| Standard | Type | Use Case |
|---|---|---|
| ERC-20 | Fungible token | Cryptocurrencies, governance tokens |
| ERC-721 | Non-fungible (NFT) | Digital art, collectibles, ownership |
| ERC-1155 | Multi-token | Games (items that are both fungible and non-fungible) |
Security
Critical vulnerabilities in source notes:
- Re-entrancy — attacker re-enters the contract before balance update; fix with checks-effects-interactions pattern or ReentrancyGuard
- Integer overflow/underflow — use Solidity 0.8+ (built-in checks) or SafeMath
- Access control — use OpenZeppelin
Ownableor role-based access - Front-running — MEV (Miner Extractable Value) and commit-reveal schemes
Development Tooling
- Hardhat — local development environment, testing, deployment
- Truffle — older alternative; Ganache for local chain
- OpenZeppelin — audited contract library (tokens, access, governance)
- Etherscan — block explorer; contract verification
Relationships
- Blockchain & Web3 — broader Web3 ecosystem
- Entrepreneurship & SaaS — DeFi protocols and Web3 product opportunities
References
- Solidity development tutorials and notes