This project is a decentralized bank (Dbank) application built with Solidity, React, and Hardhat. The smart contract enables users to deposit funds, transfer funds to other users, and request and claim withdrawals. The frontend interface is built with React and Vite, providing users a simple UI to interact with the contract functions.
- Overview
- Features
- Installation
- Usage
- Project Structure
- Smart Contract Details
- Frontend
- Backend
- License
Dbank is a Solidity-based smart contract that enables users to:
- Deposit funds and keep a record of each deposit
- Transfer funds to other users
- Request withdrawals with a specified delay time
- Claim pending withdrawals after the delay period
The frontend uses React and integrates with the smart contract to enable easy interaction for users.
- Deposits: Allows users to make deposits with a minimum amount requirement.
- Withdrawals: Users can request a withdrawal, which they can claim after a delay period.
- Transfers: Users can transfer funds directly to other addresses.
- Event Logging: Important transactions such as deposits, withdrawals, and transfers are recorded and emitted as events.
Ensure you have the following installed:
-
Clone the repository:
git clone https://github.com/yourusername/Dbank.git cd Dbank -
Backend (Hardhat):
Install backend dependencies:
cd backend npm install -
Frontend (React/Vite):
Install frontend dependencies:
cd ../frontend npm install -
Environment Variables
Create a
.envfile in the backend directory with the following (example for using Alchemy and MetaMask with Sepolia):ALCHEMY_API_URL="https://eth-sepolia.alchemyapi.io/v2/your-api-key" PRIVATE_KEY="your-private-key"
-
Compile the Smart Contract:
cd backend npx hardhat compile -
Deploy the Contract:
npx hardhat run scripts/deploy.js --network sepolia
Save the contract address generated.
-
Run the Frontend:
cd ../frontend npm run dev -
Open http://localhost:3000 in your browser.
Dbank/
├── backend/ # Contains smart contracts and Hardhat scripts
│ ├── contracts/ # Solidity contracts
│ ├── scripts/ # Deployment scripts
│ ├── test/ # Contract tests
│ ├── hardhat.config.js # Hardhat configuration
│ └── .env # Environment variables
├── frontend/ # Contains React application files
│ ├── public/ # Static assets
│ ├── src/ # React components and hooks
│ ├── App.js # Main application component
│ ├── package.json # Frontend dependencies
│ └── vite.config.js # Vite configuration
└── README.md # Project README
-
State Variables:
balances: Keeps track of each user’s balance.deposits,withdrawals,transfers: Track respective transactions.pendingPayments: Manages pending withdrawals with delay requirements.owner: Contract owner address.
-
Functions:
DepositMoney(string name): Allows users to deposit funds.Reqwithdraw(uint256 amount): Request a withdrawal.claimWithdraw(): Claim a pending withdrawal after delay.TransferMoney(uint256 amount, address to): Transfer funds to another address.checkBalance(),checkPendings(),getAllDeposits(),getAllWithdraws(),getAllTransfers(): View balance and transaction history.
The frontend is built with React, Vite, and ethers.js for interacting with the Ethereum blockchain. Key components include:
- Wallet Connection: Allows users to connect with MetaMask.
- Deposit Interface: Users can enter a deposit amount and submit.
- Withdrawal Interface: Users can request and claim withdrawals.
- Transfer Interface: Users can transfer funds to other addresses.
Dependencies include:
axiosfor API calls.ethersfor Ethereum blockchain interaction.react-router-domfor routing.tailwindcssanddaisyuifor UI styling.
cd frontend
npm run devThe backend is managed by Hardhat, which provides tools to compile, test, and deploy the smart contract. Hardhat dependencies include:
@nomicfoundation/hardhat-toolboxfor testing and deployment.solidity-coverageandhardhat-gas-reporterfor coverage and gas usage.
To run tests:
cd backend
npx hardhat test