LinuxCommandLibrary

cast

TLDR

Get the balance of an address

$ cast balance [0x...address] --rpc-url [https://eth-mainnet.g.alchemy.com/v2/key]
copy
Call a contract function (read-only)
$ cast call [0x...contract] "balanceOf(address)" [0x...holder] --rpc-url [rpc_url]
copy
Send a transaction
$ cast send [0x...contract] "transfer(address,uint256)" [0x...to] [amount] --rpc-url [rpc_url] --private-key [0x...]
copy
Decode transaction input data
$ cast 4byte-decode [0x23b872dd...]
copy
Convert wei to ether
$ cast from-wei [1000000000000000000]
copy
Convert ether to wei
$ cast to-wei [1.5]
copy
Get current gas price
$ cast gas-price --rpc-url [rpc_url]
copy
Decode ABI-encoded data
$ cast abi-decode "transfer(address,uint256)" [0x...]
copy
Lookup function signature
$ cast sig "transfer(address,uint256)"
copy

SYNOPSIS

cast subcommand [options]

DESCRIPTION

cast is a command-line tool for interacting with Ethereum and EVM-compatible blockchains. It's part of the Foundry toolkit and provides utilities for querying blockchain state, sending transactions, encoding/decoding data, and performing conversions.
Cast can interact with deployed contracts by calling view functions or sending state-changing transactions. It handles ABI encoding/decoding, making it easy to work with smart contracts from the command line.
The tool also provides utilities for working with Ethereum data formats, including conversions between wei/ether, hex/decimal, and various encoding schemes. It integrates with Etherscan-like services for signature lookups.

PARAMETERS

call contract sig [args]

Call a contract function (read-only).
send contract sig [args]
Send a transaction to a contract.
balance address
Get ETH balance of address.
block [number]
Get block information.
tx hash
Get transaction details.
receipt hash
Get transaction receipt.
gas-price
Get current gas price.
abi-encode sig [args]
ABI encode function call data.
abi-decode sig data
Decode ABI-encoded data.
sig signature
Get function selector (4 bytes).
4byte-decode selector
Look up function signature.
to-wei amount
Convert ether to wei.
from-wei amount
Convert wei to ether.
--rpc-url url
Ethereum RPC endpoint.
--private-key key
Private key for signing.
--chain chain
Chain name or ID.

CAVEATS

Requires access to an Ethereum RPC endpoint. Private keys should be handled securely (use environment variables or keystore). Gas estimation may be inaccurate for complex transactions. Some functions require an Etherscan API key for signature lookups.

HISTORY

cast is part of Foundry, developed by Georgios Konstantopoulos and the Paradigm team, announced in December 2021. Foundry was created as a fast, portable Ethereum development toolkit written in Rust, inspired by DappTools. Cast provides the CLI utilities while Forge handles testing and Anvil provides local nodes.

SEE ALSO

forge(1), anvil(1), chisel(1), geth(1)

Copied to clipboard