This project demonstrates a Fund Me smart contract, allowing the owner to deploy a contract to initiate a fundraiser and securely withdraw the raised funds.
- Foundry Installation:
Foundry is a prerequisite. Install it using the following script -
curl -L https://foundry.paradigm.xyz | bash
- Metamask MetaMask is a software cryptocurrency wallet used to interact with the Ethereum blockchain. It allows users to access their Ethereum wallet through a browser extension or mobile app, which can then be used to interact with decentralized applications.
Execute the ensuing steps to prepare the project environment:
-
Clone the Repository: Attain your local copy with:
git clone https://github.com/iamber12/fund-me-smart-contract-using-foundry
-
Compile the Project: Build the project using foundry:
forge build
- For local testnet emulation, deploy using:
forge script script/DeployFundMe.s.sol
For this you will need two things as prerequiste - - PRIVATE_KEY: Your metamask account's private key. - SEPOLIA_RPC_URL: The URL of the Sepolia testnet node you're using. You can obtain a free setup of one through Alchemy.
- Proceed with contract deployment using:
forge script script/DeployFundMe.s.sol --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY --broadcast
We mainly focus on unit and integration test in this project.
- In order to run all the tests, use the following command:
forge test
- In order to run a specific test, use the following command:
forge test --mt <function_name>
-
To conduct tests on a Sepolia network fork, use:
forge test --fork-url $SEPOLIA_RPC_URL
-
For an overview of test coverage, execute:
forge coverage
- To get an overview of the gas usage, use the following command:
forge snapshot
An application of this smart contract would look something like this-
Thanks to Cyfrin. You can find one such implementation in this repo.