Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Simple Wallet Contract

A minimal Solidity wallet implementation with basic deposit, withdrawal, and transfer functionalities. Designed for learning and testing purposes.

Features

  • 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.

Deploy

  1. Open Remix IDE.
  2. Create a new file Wallet.sol and paste the contract code.
  3. Compile with Solidity version 0.8.13 (or any ^0.8.13 compatible version).
  4. Deploy the contract using Injected Provider (e.g., MetaMask) or a local test environment.

Contract Functions

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

Events

  • 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.

Errors

  • MoneyNotEnough() – Reverts when trying to withdraw/transfer more than the balance, or deposit 0 ETH.
  • GetMoneyError() – (Unused in current code; reserved for future use.)

Admin

The deployer of the contract is set as the admin and is the only one allowed to call getContBalance().

Example Usage (Remix)

  1. Deploy the contract.
  2. Call deposit() with a value (e.g., 1 ETH) to add funds.
  3. Call balances(address) to check your balance.
  4. Call transfer("0x...", 0.1 ether) to send funds to another address.
  5. Call withdraw(0.2 ether) to withdraw funds.
  6. Admin can call getContBalance() to refresh contSum.

Security Considerations

  • 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 call with gas limits, but for production, consider using ReentrancyGuard.

License

UNLICENSED – see SPDX header.

About

Solidity+Foundry+React+Wagmi(JS)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages