Welcome to the Bank (Deposit & Withdraw) project! This is a fullstack Solidity practice project built using the Foundry framework. It demonstrates a complete DApp lifecycle—from local smart contract development and testing to a fully deployed live frontend interacting with the Sepolia testnet.
- Live Application
- Project Architecture
- Getting Started Locally
- Environment Variables
- Automation with Make
- Local Deployment (Anvil & Ganache)
- Testnet Interaction Guide
This project features a live frontend hosted on GitHub Pages that interacts directly with the smart contract deployed on the Sepolia Testnet.
🔗 Live Demo: Foundry Bank DApp
How to interact:
- Visit the link above.
- Click Connect Wallet.
- Ensure your MetaMask or Web3 Wallet is set to the Sepolia Testnet.
- Deposit and withdraw test ETH easily through the intuitive UI!
(If you need testnet funds to interact, refer to the Testnet Interaction Guide below).
The repository is logically structured to follow Foundry best practices:
src/: Contains the core smart contractBank.soldetailing the deposit and withdraw logic.test/: Contains the testing suite. We rigorously test our contract state to ensure bulletproof reliability before deployment.script/: Contains deployment scripts and the helper configuration file to streamline multi-chain deployments dynamically.
To clone and run this project locally on your machine, follow these steps:
-
Clone the repository:
git clone https://github.com/Men6d656e/01_Bank_Deposit_withdraw_by_myself.git cd 01_Bank_Deposit_withdraw_by_myself -
Install Foundry: If you haven't already, install Foundry.
-
Install Dependencies:
forge install
This project requires environment variables to deploy and interact securely. We use a .env file to manage these secrets so they are never exposed in the code.
- Locate the
.env.examplefile in the root directory. This file shows exactly what variables you need. - Create a new file named
.env:cp .env.example .env
- Fill out the
.envfile with your RPC URLs and Private Keys. (Note: Ensure you never commit your actual.envfile to version control!)
We use a Makefile so you don't have to memorize long forge commands. Below is the beginner-friendly step-by-step guide for deploying this smart contract to different networks using simple commands.
Before deploying anywhere, make sure your code compiles and passes all tests:
- Clean previous builds: Run
make clean - Run tests: Run
make test
Anvil is Foundry's built-in local blockchain. It's incredibly fast and perfect for quick testing.
- Open a new terminal and start Anvil:
anvil
- In your main project terminal, run:
make deploy-anvil
(This command uses the default Anvil keys and RPC url defined in your .env, so no interactive prompts are needed.)
Ganache provides a visual interface for blockchain state debugging.
⚠️ CRITICAL NOTE FOR GANACHE: Ganache uses an older EVM specification. Before deploying to Ganache, you must open thefoundry.tomlfile and uncomment the following line:evm_version = "paris"Without doing this, your deployment to Ganache will fail!
- Open the Ganache application and start a Workspace.
- Ensure your
GANACHE_RPC_URLis correctly set in your.env(usuallyhttp://127.0.0.1:7545). - Run the deployment command:
make deploy-ganache
- Interactive Prompt: The terminal will securely ask you to paste a private key. Copy one of the private keys from your Ganache GUI and paste it into the terminal (it will be hidden as you type).
Deploying to Sepolia makes your contract live and accessible to the world.
- Make sure your
.envhas theSEPOLIA_RPC_URL(e.g., from Alchemy or Infura) and yourEATHER_SCAN_API_KEY(to verify the contract code on Etherscan). - Run the deployment command:
make deploy-sepolia
- Interactive Prompt: The terminal will securely ask you to paste your real testnet wallet's private key (e.g., from MetaMask). Paste it in securely.
- Your contract will be deployed to Sepolia and automatically verified on Etherscan!
When interacting with the live DApp or running your own Sepolia deployment:
- Ensure your browser wallet (like MetaMask) is on the Sepolia Network.
- Need Faucets? You cannot use real ETH on testnets. To get test ETH, we recommend requesting some from the Google Ethereum Faucets or other trusted Sepolia faucet providers.
- Once your wallet is funded, you can seamlessly test the Deposit and Withdraw functions on the smart contract directly from the live application.