Skip to content

BLOCKCHAIN / WEB3 / FOUNDRY: FundMe Smart Contract Project using Foundry and Solidity. The project includes a FundMe smart contract built in Solidity, with deployment and interaction scripts using the Foundry framework. This project demonstrates how users can fund and withdraw funds from a contract.

Notifications You must be signed in to change notification settings

karolcichosz/foundry-fund-me

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FundMe Smart Contract Project

This project demonstrates a basic funding and withdrawal smart contract, FundMe, written in Solidity, along with the deployment and interaction scripts using the Foundry framework.

Getting Started

The FundMe contract allows users to send Ether to the contract and store it securely until the contract owner withdraws it. This repository contains:

  • Solidity contracts for FundMe
  • Scripts to deploy, fund, and withdraw from the contract using Foundry and forge-std
  • Comprehensive tests for contract interaction

Features

  • Fund Contract: Users can fund the contract by sending Ether.
  • Withdraw Funds: The contract owner can withdraw the funds.
  • Deployment & Interactions: Includes scripts for deploying and interacting with the contract.
  • Testing: Test the funding and withdrawal processes using Foundry's testing framework.

Requirements

  • git
    • You'll know you did it right if you can run git --version and see a response like git version x.x.x
  • foundry
    • You'll know you did it right if you can run forge --version and see a response like forge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)

Usage

Deploy

forge script script/DeployFundMe.s.sol

Testing

We talk about 4 test tiers in the video.

  1. Unit
  2. Integration
  3. Forked
  4. Staging

This repo covers #1 and #3.

forge test

or

forge test --match-test testFunctionName

or

forge test --fork-url $SEPOLIA_RPC_URL

Test Coverage

forge coverage

Deployment to a testnet or mainnet

  1. Setup environment variables

You'll want to set your SEPOLIA_RPC_URL as an environment variable. You can add it to a .env file, similar to what you see in .env.example.

  • SEPOLIA_RPC_URL: This is the URL of the Sepolia testnet node you're working with. You can get set up with one for free from Alchemy.

Optionally, add your ETHERSCAN_API_KEY if you want to verify your contract on Etherscan.

  1. Import and set up your account using cast wallet: Instead of using private keys in plain text, you can securely manage accounts with cast wallet.

    First, import your private key securely using:

cast wallet import defaultKey --interactive
cast wallet list

Once imported, you can use your account safely in any script.

  1. Get testnet ETH

Head over to faucets.chain.link and get some testnet ETH. You should see the ETH show up in your wallet.

  1. Deploy
forge script script/DeployFundMe.s.sol --rpc-url $SEPOLIA_RPC_URL --account defaultKey --sender $SENDER --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY -vvvv

Scripts

After deploying to a testnet or local net, you can run the scripts.

Using cast with a locally deployed contract example:

cast send <FUNDME_CONTRACT_ADDRESS> "fund()" --value 0.1ether --account defaultKey

or

forge install Cyfrin/foundry-devops --no-commit
forge script script/Interactions.s.sol --rpc-url $SEPOLIA_RPC_URL --account defaultKey --sender $SENDER --broadcast -vvvv

Withdraw

cast send <FUNDME_CONTRACT_ADDRESS> "withdraw()" --account defaultKey

Estimate gas

You can estimate how much gas things cost by running:

forge snapshot

And you'll see an output file called .gas-snapshot.

Formatting

To run code formatting:

forge fmt

Additional Info:

Chainlink-brownie-contracts is an official repo. The repository is owned and maintained by the Chainlink team for this very purpose and receives releases from the proper Chainlink release process. You can see it's still the smartcontractkit organization as well.

https://github.com/smartcontractkit/chainlink-brownie-contracts

About

BLOCKCHAIN / WEB3 / FOUNDRY: FundMe Smart Contract Project using Foundry and Solidity. The project includes a FundMe smart contract built in Solidity, with deployment and interaction scripts using the Foundry framework. This project demonstrates how users can fund and withdraw funds from a contract.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published