A secure and production-style ERC20 staking smart contract designed for decentralized finance (DeFi) applications.
This project demonstrates best practices in Solidity development, smart contract security, and on-chain reward distribution.
This staking pool allows users to stake ERC20 tokens and earn rewards over time.
Rewards are distributed proportionally based on the user's stake and staking duration.
The contract is built using OpenZeppelin libraries and follows modern Solidity security patterns.
- ERC20 token staking
- Time-based reward distribution
- Secure reward calculation
- Reentrancy protection
- Owner-controlled reward rate
- Compatible with Remix IDE
-
StakingPool.sol
- Core staking logic
- Reward calculation per token
- Secure stake, withdraw, and claim functions
-
MockERC20.sol
- Test ERC20 token for local testing and demos
- Uses OpenZeppelin
ReentrancyGuardto prevent reentrancy attacks - Uses OpenZeppelin
Ownablefor access control - Prevents zero-amount staking and withdrawals
- Immutable token addresses for safety
- Open Remix IDE
- Create a new workspace
- Add both contracts to the
contractsfolder - Compile using Solidity version
0.8.20 - Deploy
MockERC20 - Deploy
StakingPoolusing the MockERC20 address - Approve tokens before staking
- Stake tokens and claim rewards
approve(stakingPoolAddress, amount)
stake(amount)
claimReward()