Welcome to this educational repository that complements solidity-by-example.org! This repository provides hands-on examples with Foundry testing to help you learn Solidity through practical experience.
This repository aims to:
- Provide practical, runnable examples of Solidity concepts
- Demonstrate best practices through comprehensive tests
- Help you understand Solidity patterns through interactive learning
Each example in this repository follows this structure:
- A Solidity contract demonstrating a concept
- Comprehensive tests showing different use cases
- Comments explaining key concepts and potential pitfalls
- Install Foundry:
curl -L https://foundry.paradigm.xyz | bash
foundryup
- Clone this repository:
git clone https://github.com/larrettgee/solidity-by-example.git
cd solidity-by-example
- Install dependencies:
forge install
- Build all contracts:
forge build
- Run all tests:
forge test
- Run tests for a specific example:
forge test --match-contract ExampleContractTest
- Basic Concepts
- Variables and Types
- Functions
- Control Flow
- Intermediate Concepts
- Events and Logging
- Error Handling
- Inheritance
- Advanced Concepts
- Assembly
- Storage Patterns
- Gas Optimization
This project uses Foundry, which includes:
- Forge: Testing framework
- Cast: Chain interaction tool
- Anvil: Local testnet node
- Chisel: Solidity REPL
For detailed documentation on Foundry, visit book.getfoundry.sh
Contributions are welcome! If you have an example you'd like to add:
- Fork the repository
- Create a new branch for your example
- Add your contract and tests
- Submit a PR with a clear description of what your example teaches
This project is licensed under MIT - see the LICENSE file for details
Happy learning! If you find this helpful, please give it a ⭐️