This project implements an Ether staking smart contract that allows users to stake Ether for a specified period, earn rewards based on the duration of the stake, and withdraw their staked Ether along with earned rewards after the staking period ends.
This smart contract allows users to stake their Ether in the contract and earn rewards proportional to the duration of their stake. The contract ensures the safety of user funds and calculates rewards accurately based on the staking time. Users can withdraw their initial stake along with the earned rewards once the staking period has ended.
- Staking Ether: Users can stake Ether by sending a transaction to the contract.
- Time-Based Rewards: Users earn rewards based on the duration of their stake.
- Withdrawals: After the staking period, users can withdraw both their staked Ether and the earned rewards.
- Security: The contract implements security measures to protect user funds and prevent vulnerabilities like reentrancy attacks.
-
Clone the Repository:
git clone https://github.com/ceasermikes002/SaveEther-SmartContract.git cd ether-staking-contract
-
Install Dependencies:
npm install
-
Set Up Environment Variables: Create a
.env
file in the root directory to store your environment variables:PRIVATE_KEY=your-private-key-on-lisk-sepolia-network
-
Compile the Smart Contract:
npx hardhat compile
-
Deploy to Local Network: Start a local Hardhat network:
npx hardhat node
Deploy the contract:
npx hardhat id scripts/deploy.js --network localhost
-
Deploy to Testnet: Ensure your
hardhat.config.js
is set up with the appropriate network configuration (e.g., Ropsten, Rinkeby). Deploy to a testnet:./ignition/modules/Deploy.js --network lisk-sepolia
The test suite covers all major functionalities, including staking, reward calculation, and withdrawals.
- Reentrancy Attacks: The contract follows the checks-effects-interactions pattern to prevent reentrancy attacks.
- Gas Efficiency: The contract is optimized for gas efficiency, ensuring that operations are executed with minimal gas consumption.
- Error Handling: Proper error handling mechanisms are in place to revert transactions if any issues are detected.