How openzeppelin/ethernaut works
Project type and purpose
• This is a full-stack Web3 dApp (a “wargame”) comprising:
• A React/Redux frontend (client/)
• A suite of Solidity smart contracts (contracts/)
• A local or public Ethereum JSON-RPC network (ganache, Hardhat network, or Sepolia)
• Players load levels (each level is a smart contract) in the browser and interact with them via Metamask or another Web3 provider.
File structure
• Top-level:
• client/ – React application, source code, components, actions, reducers, styles, gamedata JSON
• contracts/ – Foundry/forge Solidity project, source, tests, libraries (openzeppelin, forge-std), deployment config
• deps/ – third-party JS deps (highlight.js)
• Config/deployment/scripts – netlify.toml, GitHub workflows, client/scripts for deploy & docs
• Patterns:
• React + Redux for UI and state management
• Middleware layer in client to orchestrate Web3 calls (activateLevel, loadEthernautContract, syncPlayerProgress, etc.)
• Foundry for compiling/testing/deploying contracts
• Deployment files: contracts/remappings.txt, foundry.toml, deploy.*.json series to track deployed instances
Key insights from README
• Three components must run in concert:
1. Local or remote Ethereum test network
2. Contracts compiled & deployed to that network
3. React client configured to point at that network
• Standard workflows: compile:contracts, deploy:contracts, start:ethernaut
a. Main components
• User’s Browser + Metamask (Web3 wallet)
• React/Redux Frontend (client/src)
• JSON-RPC Provider (Ganache/Hardhat or Sepolia)
• Smart Contracts on EVM (contracts/src + deployed instances)
• Off-chain gamedata JSON files (client/src/gamedata)
• Deployment/CI pipelines (GitHub Actions, Netlify)
b. Relationships & interactions
1. User → Browser → React UI
2. React dispatches Redux actions → middleware invokes Web3 calls via ethers.js/web3.js → Metamask → RPC provider
3. RPC provider routes to EVM → execute smart contract functions → return transaction receipts or view data
4. React consumes contract responses and gamedata JSON → updates Redux store → re-renders UI
5. Deployment scripts (client/scripts & Foundry) → compile & deploy contracts → write addresses to deploy.*.json
c. Architectural patterns & principles
• Separation of concerns: UI vs. state management vs. blockchain interaction
• Redux middleware abstracts Web3 logic (network selection, contract loading, transaction submission, stats sync)
• Immutable on-chain state (contracts) vs. ephemeral UI state (Redux store)
• CI/CD for testing contracts (yarn test:contracts) and building/deploying frontend (Netlify, GitHub Actions)
d. Key technologies & frameworks
• Frontend: React, Redux, React-Redux, react-router (withRouter HOC), CSS modules
• Blockchain: Solidity contracts managed via Foundry/forge, OpenZeppelin libraries
• Web3: ethers.js or web3.js via middleware, Metamask as provider
• Build & deploy: yarn, Netlify, GitHub Actions