A minimal Solidity wallet implementation with basic deposit, withdrawal, and transfer functionalities. Designed for learning and testing purposes.
- Deposit – Send ETH to the contract, credited to the caller's balance.
- Withdraw – Withdraw a specified amount of ETH from your own balance.
- Transfer – Send ETH from your balance to another address.
- Contract Balance Query – Only the admin can update and view the total contract balance.
- Fallback & Receive – Handles direct ETH transfers and unknown function calls gracefully.
- Open Remix IDE.
- Create a new file
Wallet.soland paste the contract code. - Compile with Solidity version
0.8.13(or any^0.8.13compatible version). - Deploy the contract using Injected Provider (e.g., MetaMask) or a local test environment.
| Function | Description | Access |
|---|---|---|
deposit() |
Payable; adds sent ETH to the caller's balance. | Public |
withdraw(uint256 amount) |
Withdraws amount ETH from caller's balance to their address. |
Public |
transfer(address to, uint256 amount) |
Transfers amount from caller's balance to to. |
Public |
getContBalance() |
Updates contSum with the contract's current ETH balance. |
Only admin |
balances(address) |
View the balance of a specific address. | Public view |
Deposit(address indexed owner, uint256 amount)– Emitted on successful deposit.Withdraw(address indexed owner, uint256 amount)– Emitted on successful withdrawal.Transfer(address indexed owner, address indexed to, uint256 amount)– Emitted on successful transfer.
MoneyNotEnough()– Reverts when trying to withdraw/transfer more than the balance, or deposit 0 ETH.GetMoneyError()– (Unused in current code; reserved for future use.)
The deployer of the contract is set as the admin and is the only one allowed to call getContBalance().
- Deploy the contract.
- Call
deposit()with a value (e.g., 1 ETH) to add funds. - Call
balances(address)to check your balance. - Call
transfer("0x...", 0.1 ether)to send funds to another address. - Call
withdraw(0.2 ether)to withdraw funds. - Admin can call
getContBalance()to refreshcontSum.
- This contract is not audited; do not use with real funds in production.
- No access control on
deposit()beyond the caller's address. - Reentrancy is prevented by using
callwith gas limits, but for production, consider usingReentrancyGuard.
UNLICENSED – see SPDX header.