Cast

Cast is a Swiss Army knife for interacting with Ethereum applications from the command line. You can make smart contract calls, send transactions, or retrieve any type of chain data - all from your command-line!

The cast binary can be used both within and outside of a Foundry project.

Cast is part of the Foundry suite and is installed alongside forge, chisel, and anvil. If you haven’t installed Foundry yet, see Foundry installation.

Getting started

Here are a few examples of what you can do:

Check the latest block on Ethereum Mainnet:

cast block-number --rpc-url https://eth.merkle.io

Check the Ether balance of vitalik.eth

cast balance vitalik.eth --ether --rpc-url https://eth.merkle.io

Replay and trace a transaction

cast run 0x9c32042f5e997e27e67f82583839548eb19dc78c4769ad6218657c17f2a5ed31 --rpc-url https://eth.merkle.io

Optionally, pass --etherscan-api-key <API_KEY> to decode transaction traces using verified source maps, providing more detailed and human-readable information.

Retrieve the total supply of the DAI token

$ cast call 0x6b175474e89094c44da98b954eedeac495271d0f "totalSupply()(uint256)" --rpc-url https://eth-mainnet.alchemyapi.io/v2/Lc7oIGYeL_QvInzI0Wiu_pOZZDEKBrdf
3459158698614939444940942170 [3.459e27]

Decode calldata

$ cast 4byte-decode 0x1F1F897F676d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003e7
1) "fulfillRandomness(bytes32,uint256)"
0x676d000000000000000000000000000000000000000000000000000000000000
999

Send messages between two Anvil accounts

cast send --private-key <PRIVATE_KEY> 0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc $(cast from-utf8 "hello world") --rpc-url http://127.0.0.1:8545/

Features

TODO: add comprehensive list of features


📚 Reference

See the cast Reference for a complete overview of all the available subcommands.