Language basics
28 steps in 9 sets of Solidity.
Solidity is the language of the Ethereum Virtual Machine: contracts that hold funds and enforce rules once deployed, where a bug is not a ticket but a loss, and every line costs gas someone pays. That discipline shapes the whole dialect — sized integers, explicit data locations, checked arithmetic since 0.8, custom errors over strings, and patterns like pull-payments that exist purely because the adversarial environment demands them.
This tour types the working language through a community orchard cooperative: contract shape and value types, view against pure, constant and immutable, mappings and structs and enums, require and typed custom errors, modifiers, events with indexed topics, payable and the withdraw pattern, data locations, gas-aware loops, inheritance and interfaces and abstract contracts, libraries with using-for, try/catch on external calls, keccak256 fingerprints, the block context, unchecked arithmetic, and the fallback pair. The Encore deploys three complete contracts: the membership roll, an hours-based harvest split, and a one-member-one-vote ballot.
Contracts
- The contract shapeA contract is state plus functions, deployed at an address.
- Value typesSized integers, address, bool, bytes32: the primitives.
- view and pureview reads state, pure touches none; offchain both are free.
- constant and immutableBaked at compile time, or fixed once at deployment.
Storage
- MappingsThe key-value store; missing keys read as zero.
- Structs and arraysBundle fields, then push them into a growing list.
- EnumsName the phases; walk them in order with a cast.
Guards
- require and revertGuards with messages, or typed custom errors.
- ModifiersWrap a function; _ marks where the body runs.
- Custom errorsTyped context, cheaper than revert strings.
Ether & events
- EventsThe log: indexed fields become searchable topics.
- payable and receiveAccepting ether is opt-in; receive catches plain sends.
- The withdraw patternPull, don't push: zero the balance before sending.
Data & gas
- Data locationstorage persists, memory is scratch, calldata is the call.
- Loops and gasEvery pass costs gas; bounded arrays keep loops honest.
- unchecked0.8 checks arithmetic; unchecked opts out where safe.
Composition
- Inheritancevirtual invites an override; super reaches the parent.
- InterfacesThe shape of a contract you only know by address.
- Abstract contractsLeave a hole a child must fill.
- LibrariesPure helpers, grafted onto a type with using-for.
The environment
- The global contextmsg.sender, block.timestamp, block.number: the environment.
- keccak256The fingerprint of anything, via abi.encodePacked.
- try/catchGuard external calls that may revert.
Surfaces
- Getters and tuplespublic state writes its own getter; functions return tuples.
- fallbackThe catch-alls: fallback for unknown calls, receive for ether.
Encore
- coop_membership.solThe cooperative roll: join, pay dues, stand for steward.
- harvest_split.solSplit proceeds by picking hours, paid by the pull pattern.
- orchard_votes.solOne member one vote: propose, vote to deadline, tally.