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
$ forge test
$ forge fmt
$ forge snapshot
$ anvil
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
$ cast <subcommand>
$ forge --help
$ anvil --help
$ cast --help
cast --to-base [number] dec
Modify env Run source .env echo $RPC_URL
anvil
Adding rpc and hidden private key
forge create SimpleStorage --rpc-url http://127.0.0.1:8545 --interactive
forge create SimpleStorage --rpc-url http://127.0.0.1:8545 --private-key 0xasdasd
Deploy to Anvil by default and hidden private key
forge create SimpleStorage --interactive
forge script script/DeploySimpleStorage.s.sol --rpc-url http://127.0.0.1:8545 --broadcast --private-key [private-key]
Using the .env variables
forge script script/DeploySimpleStorage.s.sol --rpc-url $RPC_URL --broadcast --private-key $PRIVATE_KEY
NOTE: Having the .env file is cool in development but for production, use --interactive for the private key
Interact with contracts that already have been deployed
Cast
cast send 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 "store(uint256)" 123 --rpc-url $RPC_URL --private-key $PRIVATE_KEY
cast call 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 "retrieve()"
npx thirdweb deploy
forge fmt
forge test -vv
forge test -vv --fork-url $SEPOLIA_RPC_URL
forge test --match-test testPriceFeedVersionIsAccurate
// What can we do to work with addresses outside our system? // 1. Unit // - Testing a specific part of our code // 2. Integration // - Testing how our code works with other parts of our code // 3. Forked // - Testing our code on a simulated real environment // 4. Staging // - Testing our code in a real environment that is not prod
forge test --match-test testPriceFeedVersionIsAccurate -vvv --fork-url $SEPOLIA_RPC_URL
forge coverage -vvv --fork-url $SEPOLIA_RPC_URL