A decentralized time-locked ETH staking dApp built with Solidity, JavaScript, HTML, CSS, and Ethers.js.
Users can stake ETH for a fixed period and earn rewards based on the contract's APY. Funds can only be withdrawn after the selected lock period has ended.
- Connect wallet with MetaMask
- Stake ETH for a fixed duration
- Earn APY-based rewards
- View staking balance and reward
- View staking start and unlock time
- Withdraw ETH after the lock period
- Owner-controlled APY
- Reentrancy protection
- On-chain staking state and events
Connect Wallet
↓
Choose Lock Duration
↓
Stake ETH
↓
Funds Locked
↓
Rewards Accumulate
↓
Lock Period Ends
↓
Unstake
↓
Receive Stake + Reward
Each user can have one active stake at a time. The contract stores the user's deposited amount, start timestamp, unlock timestamp, and staking status.
The contract uses simple interest, not compound interest:
Reward = (Staked Amount × APY × Days) / (100 × 365)
For example, with 1 ETH at 10% APY for 30 days:
Reward ≈ 0.0082 ETH
Rewards are calculated from the elapsed staking time.
The contract provides:
stake(uint time)
unstake()
calculateReward(address user)
seeUserReward(address user)
changeAPY(uint8 APY)
ownerWithdraw()The APY can be changed by the contract owner and is limited to a maximum of 30%.
- Custom Solidity errors
- Reentrancy guard
- Owner access control
- Checks before ETH withdrawal
- User state reset after withdrawal
Note:
ownerWithdraw()allows the owner to withdraw the entire contract balance. This is an important trust assumption and means the contract is not trustless for user funds.
- Solidity
^0.8.21 - JavaScript
- HTML / CSS
- Ethers.js
- MetaMask
TimeStakingDapp/
├── TimeStaking.sol
├── index.html
├── script.js
├── dashboard.html
├── dashboard.js
├── status.html
├── status.js
└── README.md
The project includes separate pages for staking, dashboard information, and staking status.
git clone https://github.com/mohit-solidity/TimeStakingDapp.git
cd TimeStakingDappOpen index.html in a browser with MetaMask installed.
The frontend uses Ethers.js to connect to the deployed contract and interact with its staking functions.
This project is for educational purposes and has not been professionally audited. Do not use it with significant real funds.
Mohit Sharma
Blockchain Developer | Solidity • React.js • Ethers.js