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.
$ forge build- Simple
$ forge test - Verbose
$ forge test -vvvv- The more
vwill be used (for a maximum of 4), the more verbosity output will be printed
- The more
- Run specific test
forge test --match-test <regex>
- Example
forge test --match-test testPriceFeedVersionIsAccurate
- Example
- Run test on a forked chain
forge test --fork-url <your_forked_chain_rpc_url>
- Example
forge test --fork-url $SEPOLIA_RPC_URL
- Example
- Run test with coverage
forge coverage
$ forge fmt$ forge snapshot- Inspect the
storage layoutof a contractforge inspect <contract_name> storageLayout
- Example
forge inspect FundMe storageLayout
- Example
$ anvil- 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
FundMecontract and the relatedInteractions:FundFundMecontractforge 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 <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)"
- Example
$ forge --help
$ anvil --help
$ cast --help- 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
- Example
- Latest version
- 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
- 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.