Skip to main content

Simple Vault Contract

A basic DeFi vault that accepts ETH deposits and allows withdrawals. A basic DeFi vault that accepts ETH deposits and allows withdrawals.

Explanation

This vault demonstrates core DeFi primitives: deposit, withdraw, and balance tracking. Security notes:
  • Uses the checks-effects-interactions pattern: state is updated before the external call.
  • msg.sender.call{value: amount} sends ETH safely (vs. transfer which has gas limits).
  • Always validate amounts with require before state changes.
In production, add reentrancy guards, events, and proper access controls.

Code


Canonical knowledge ID: code-example:simple-vault-contract