Progressive smart contract exercises exploring storage patterns, access control, and on-chain data structures in Solidity.
Each version builds on the previous one, adding a new concept while keeping the code simple.
| Contract | Concept | Key Addition |
|---|---|---|
| Storage1 | Elementary operations | pure function (two args) and view function (one arg) for multiplication |
| Storage2 | Gas cost observation | Same logic as Storage1, used to compare gas between set() and read-only calls |
| Storage3 | Error handling | Overflow, underflow and division-by-zero checks with require |
| Storage4 | Data type cost comparison | Separate uint8, uint16, uint128, uint256 variables to compare gas |
| Storage5 | Read restriction | Only the last writer can read the value; others receive 0 |
| Storage6 | Constructor | Initial value set on deployment via constructor(uint) |
| Storage7 | Owner-only writes | onlyOwner modifier restricts set() to the deployer |
On-chain contact book where each entry holds an ETH address and a name. Versions add progressive access control and search capabilities.
| Contract | Concept | Key Addition |
|---|---|---|
| Agenda1 | Basic entries | Global contact list with addContact and getContact |
| Agenda2 | Per-user storage | mapping(address => Contact[]) gives each user their own book |
| Agenda3 | Edit and delete | editContact and deleteContact with swap-and-pop pattern |
| Agenda4 | Time-limited delegation | grantAccess(delegate, seconds) for read-only access with expiry |
| Agenda5 | Search | searchByAddress and searchByName using keccak256 for string comparison |
The StorageContracts file demonstrates how Solidity handles state writes versus read-only calls. Writing to storage (SSTORE) costs around 20,000 gas for a cold slot, while pure and view functions cost zero gas when called externally. Storage4 shows that the EVM always operates on 256-bit words, so smaller types like uint8 do not reduce gas per individual slot.
The AgendaContracts file explores three levels of access control. Per-user isolation is achieved through msg.sender as the mapping key, ensuring no user can access another's data. Time-limited delegation uses block.timestamp to auto-expire permissions. Owner-only restriction in Storage7 uses a modifier that checks msg.sender against the deployer address stored at construction.
| Component | Role |
|---|---|
| Remix IDE | Development environment for compiling, deploying and testing all contracts |
| Solidity Compiler 0.8+ | Provides built-in checked arithmetic (overflow/underflow protection) |
| EVM (JavaScript VM) | Local blockchain used in Remix for testing without real gas costs |
| GitHub | Version control and repository hosting |
- Language: Solidity 0.8+
- IDE: Remix IDE (browser-based)
- Runtime: EVM-compatible JavaScript VM (Remix default)
- Version Control: Git, GitHub
- Incremental contract versions — each file progresses from basic to advanced, one concept at a time
- Pure vs view comparison — demonstrates the gas difference between state-reading and stateless functions
- Built-in overflow protection — leverages Solidity 0.8 checked arithmetic instead of SafeMath
- Swap-and-pop deletion — avoids gaps in dynamic arrays when removing contacts
- Time-based delegation — read-only access expires automatically using
block.timestamp - String search via hashing — uses
keccak256to compare strings since Solidity lacks native string equality
All contracts are tested manually in Remix IDE using the JavaScript VM environment. Each contract is deployed, and functions are called with different accounts from the Remix account selector to verify access control. Gas costs are compared by reading the transaction and execution cost fields in the Remix console. Error cases (overflow, division by zero, unauthorized access) are tested by triggering reverts and confirming the expected error messages.
-
Open Remix IDE
-
Create the contract files in the root of your workspace:
StorageContracts.sol AgendaContracts.sol -
Select compiler version
0.8.0or higher and compile both files -
In the Deploy tab, select Remix VM as the environment
-
Deploy any contract and interact with it using the generated UI
Built for Ethereum / EVM-compatible chains.