Skip to content

Repository files navigation

Foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.

Foundry consists of:

  • Forge: Ethereum testing framework (like Truffle, Hardhat and DappTools).
  • Cast: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
  • Anvil: Local Ethereum node, akin to Ganache, Hardhat Network.
  • Chisel: Fast, utilitarian, and verbose solidity REPL.

Documentation

https://book.getfoundry.sh/

Usage

Build

$ forge build

Test

  • Simple
    $ forge test
  • Verbose
    $ forge test -vvvv
    • The more v will be used (for a maximum of 4), the more verbosity output will be printed
  • Run specific test
    forge test --match-test <regex>
    • Example
      forge test --match-test testPriceFeedVersionIsAccurate
  • Run test on a forked chain
    forge test --fork-url <your_forked_chain_rpc_url>
    • Example
      forge test --fork-url $SEPOLIA_RPC_URL
  • Run test with coverage
    forge coverage

Format

$ forge fmt

Gas Snapshots

$ forge snapshot

Inspect Contract

  • Inspect the storage layout of a contract
    forge inspect <contract_name> storageLayout
    • Example
      forge inspect FundMe storageLayout

Anvil

$ anvil

Deploy

  • Simple
    $ forge script script/FundMe.s.sol:FundMeScript --rpc-url <your_rpc_url> --private-key <your_private_key>
  • Build deploy transaction without sent it (test if the script goes well)
    forge script script/FundMe.s.sol:FundMeScript
  • Deploy FundMe contract and the related Interactions:FundFundMe contract
    forge script script/FundMe.s.sol \
      --force \
      --broadcast \
      --rpc-url http://localhost:8545 \
      --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
    forge script script/Interactions.s.sol:FundFundMe \
      --force \
      --broadcast \
      --rpc-url http://localhost:8545 \
      --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

Cast

$ cast <subcommand>
  • Get the contract's storage at specified slot
    cast storage <contract_address> <storage_slot_number>
  • Get the function's selector
    cast sig "<function-signature>"
    • Example
      cast sig "getAddressToAmountFunded(address)" 

Help

$ forge --help
$ anvil --help
$ cast --help

Install dependencies

  • Chainlink
    • Latest version
      forge install smartcontractkit/chainlink-brownie-contracts
    • Specific version
      forge install smartcontractkit/chainlink-brownie-contracts@<version>
      • Example
        forge install smartcontractkit/chainlink-brownie-contracts@1.1.1
  • foundry-devops
    • A repo to get the most recent deployment from a given environment in foundry. This way, you can do scripting off previous deployments in solidity.
      forge install Cyfrin/foundry-devops

About

SmartContract that allows users to deposit and withdraw ETH

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages