Foundry (Cheat Sheet)
Foundry comes with four main binaries
forge
,
cast
,
anvil
,
and
chisel
.
Forge tests, builds, and deploys your smart contracts.
Cast is Foundry’s command-line tool for performing Ethereum RPC calls. You can make smart contract calls, send transactions, or retrieve any type of chain data - all from your command-line!
Anvil is a local testnet node shipped with Foundry. You can use it for testing your contracts from frontends or for interacting over RPC.
Chisel is an advanced Solidity REPL shipped with Foundry. It can be used to quickly test the behavior of Solidity snippets on a local or forked network.
Here are links to the commands you can run with each of these binaries:
Installation
Running foundryup
by itself will install the latest (nightly)
precompiled binaries
: forge
, cast
, anvil
, and chisel
. See foundryup --help
for more options, like installing from a specific version or commit.
Source: book.getfoundry.sh
cast
Generate event signature
Source: book.getfoundry.sh
$ cast sig-event "Transfer(address indexed from, address indexed to, uint256 amount)"
0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
$ cast sig-event "event ValidatorGroupVoteActivated(address indexed account,address indexed group,uint256 value,uint256 units)"
0x45aac85f38083b18efe2d441a65b9c1ae177c78307cb5a5d4aec8f7dbcaeabfe
For example, when filtering event logs using topic0
on
dune.com
.
SELECT *
FROM celo.logs
WHERE contract_address = 0x8d6677192144292870907e3fa8a5527fe55a7ff6 -- ElectionProxy
AND topic0 = 0x45aac85f38083b18efe2d441a65b9c1ae177c78307cb5a5d4aec8f7dbcaeabfe -- ValidatorGroupVoteActivated
Convert decimal to hex
Source: book.getfoundry.sh
$ cast to-hex "22584960"
0x1589e80
For example, block numbers must be in hex representation in JSON-RPC requests:
{
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [
{
"fromBlock": "0x1589e80",
"toBlock": "0x1589e80"
}
],
"id": 0
}