EthWallet is a smart contract that allows users to deposit, withdraw, and transfer ETH between accounts while charging a 1% transaction fee. It also demonstrates how to connect two smart contracts by delegating fee calculation to an external contract.
- 🔹 Deposit & Withdraw ETH: Users can securely deposit and withdraw their ETH.
- 🔹 Transfer with Fee: ETH transfers between users are charged a 1% fee.
- 🔹 Connected Smart Contracts: Fee calculation is delegated to an external contract (
CalculateFees). - 🔹 Fee Management: The contract owner can withdraw accumulated transaction fees.
- 🔹 Access Control: Only the owner can check other users' balances or withdraw fees.
- Solidity Version:
^0.8.24 - External Contract:
CalculateFeesfor fee calculation. - Key Functions:
deposit(): Deposits ETH into the contract.withdraw(uint256 amount): Withdraws ETH up to the user's balance.transfer(uint256 amount, address to): Transfers ETH with a 1% fee.getYourBalance(): Returns the caller's balance.getAnyBalance(address wallet): Allows the owner to check any balance.withdrawFees(): Allows the owner to withdraw collected fees.
- Open Remix IDE.
- Create two Solidity files:
EthWallet.solandCalculateFees.sol. - Compile both contracts using Solidity 0.8.24.
- Deploy
CalculateFeesfirst and copy its address. - Deploy
EthWallet, passing theCalculateFeescontract address to its constructor.
- Call
deposit()and send ETH. - Check the contract balance to verify the deposit.
- Call
transfer(amount, to). - Ensure 1% fee is deducted.
- Verify balances of sender and receiver.
- Call
withdraw(amount). - Ensure the requested amount is transferred back.
- Call
getYourBalance()to check your balance. - The owner can call
getAnyBalance(wallet)to check another address.
- Call
withdrawFees(). - Ensure the owner receives the collected fees.
This project is licensed under LGPL-3.0-only.