Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
Foundry consists of:
This repository contains a Fund Me project built using Foundry for smart contract development and Vite + React for the frontend.
Before you begin, ensure you have the following installed:
Clone the repository:
git clone https://github.com/mtmarctoni/foundry-fundme.git
cd foundry-fundme
Install Foundry dependencies (using Makefile):
make install
Install frontend dependencies:
cd frontend
npm install
cd ..
Open a new terminal and start the Anvil local blockchain:
```bash
anvil
```
This will usually start a local Ethereum network on http://127.0.0.1:8545
.
Important: Ensure you add this url to your .env file for the 'HOST_ADDRESS' variable.
In a separate terminal, deploy the Fund Me contract using Foundry in the anvil local network:
```bash
make deploy-host
```
This will deploy the contract to the local anvil network. After successful deployment, you will see the contract address in the terminal output.
Update the frontend configuration with the deployed contract address.
Locate the deploy contract address. It will be located in foundry-fundme/broadcast/FundMe.s.sol/31337/run-latest.json
after deployment.
{
//...
"contractName": "FundMe",
"contractAddress": "0xYourContractAddress"
//...
}
Copy the contract address.
Navigate to the frontend/src/config/contract-address.json
file.
Update the contractAddress
with the copied values.
Important: Ensure you replace 0xYourContractAddress
with the actual values from your deployment.
Navigate to the frontend
directory and start the Vite development server:
```bash
cd frontend
npm run dev
```
This will start the React application, and you can access it in your browser at the URL displayed in the terminal (usually http://localhost:5173
).
You can now interact with the Fund Me smart contract through the frontend interface. You can fund the contract, withdraw funds, and view the contract's balance and owners.
The Makefile uses environment variables defined in a .env
file. Create a .env
file in the root directory of the project and add your configuration:
HOST_ADDRESS="http://127.0.0.1:8545"
DEFAULT_ANVIL_KEY=""
SEPOLIA_RPC_URL=""
ETHERSCAN_API_KEY=""
To run the smart contract tests:
forge test -vvvv