A decentralized staking application built on Ethereum that demonstrates smart contract development, time-based logic, and threshold mechanisms. This project is part of the SpeedRunEthereum challenges.
This staking dApp allows users to pool Ether together with a deadline and threshold mechanism. If the threshold is met before the deadline, all funds are sent to an external contract for completion. If not, users can withdraw their individual contributions.
- Time-bound Staking: 72-hour staking period from contract deployment
- Threshold Mechanism: Requires 1 ETH minimum to complete successfully
- Conditional Execution: Automatic fund distribution or withdrawal enablement
- Event Emission: Full transparency of staking activities
- Direct ETH Transfers: Users can stake by simply sending ETH to the contract
The project consists of two main contracts:
The main contract that handles all staking logic, including:
- User balance tracking
- Deadline and threshold validation
- Conditional execution based on success criteria
- Withdrawal mechanism for failed stakes
A simple contract that serves as the completion target when staking succeeds.
- Staking Phase: Users can stake ETH during the 72-hour window
- Execution Phase: After the deadline, anyone can call
execute()- If ≥ 1 ETH was staked: All funds go to the external contract ✅
- If < 1 ETH was staked: Withdrawals become available ❌
- Withdrawal Phase: Users can reclaim their ETH if the threshold wasn't met
stake(): Accept ETH deposits and update user balancesexecute(): Determine success/failure and distribute funds accordinglywithdraw(): Allow users to reclaim funds if staking failedtimeLeft(): Display remaining time in the staking periodreceive(): Enable direct ETH transfers to stake automatically
- Access Control:
notCompletedmodifier prevents actions after completion - Input Validation: Zero address checks and proper require statements
- Reentrancy Protection: Simple transfer patterns without callbacks
- State Management: Clear separation between staking and withdrawal phases
threshold: Constant 1 ETH requirementdeadline: 72 hours from deploymentbalances: Individual user stake trackingopenForWithdraw: Withdrawal availability flag
Stake(address indexed staker, uint256 deposit): Tracks all staking activity
- Node.js (v16 or higher) and yarn
- Scaffold-ETH 2 framework
- MetaMask or similar wallet
- Git for version control
# Clone the scaffold-eth 2 repository
git clone https://github.com/scaffold-eth/scaffold-eth-2.git staking-challenge
cd staking-challenge
# Install dependencies
yarn install
# Start your local blockchain
yarn chain
# In a new terminal, deploy the contracts
yarn deploy
# In another terminal, start the frontend
yarn start# Run all tests
yarn test- Successful staking scenarios
- Failed staking and withdrawal flows
- Time-based execution logic
- Edge cases and error conditions
This project demonstrates proficiency in:
- Solidity Development: Advanced contract patterns and modifiers
- Time-based Logic: Deadline mechanisms and conditional execution
- State Management: Complex multi-phase contract workflows
- Event Handling: Proper logging and frontend integration
- Security Best Practices: Input validation and access control
- Gas Optimization: Efficient storage patterns and function design
- Staker Contract:
0x333935AC52d6ecb67407478841D778B52E04d9b8 - ExampleExternalContract:
0x8aaB1AdFd7e261b0E5b852Efc4a93251a27AE3b4
- Staker Contract on Etherscan (sepolia.etherscan.io/address/0x333935AC52d6ecb67407478841D778B52E04d9b8)
- ExampleExternalContract on Etherscan (sepolia.etherscan.io/address/0x8aaB1AdFd7e261b0E5b852Efc4a93251a27AE3b4)
- ✅ Smart contracts deployed and verified
- ✅ Frontend integration complete
- ✅ All tests passing
- ✅ Proper documentation and comments
- ✅ Gas optimizations implemented
Built with ❤️ as part of the Ethereum developer journey