An introduction to Foundry and using the cast function, replacing complex scripts that may otherwise require multiple rpc calls and other functions in between with a single command.
Use this file to discover all available pages before exploring further.
Foundry is a fast and modular toolkit for Ethereum application development written in Rust. It provides four main command-line tools—forge, cast, anvil, and chisel—to streamline everything from project setup to live-chain interactions.Among these, cast serves as your “Swiss-army knife” for JSON-RPC calls, letting you execute tedious day-to-day tasks (like sending raw transactions, querying balances, fetching blocks, and looking up chain metadata) with simple, consistent commands instead of verbose curl scripts.This guide walks you through installing Foundry, configuring your environment, and using the most common cast commands to accelerate your development workflow.
To avoid passing the --rpc-url flag with every command, you can set defaults in a foundry.toml file. This file can be placed in your project’s root directory for project-specific settings, or you can create a global configuration at ~/.foundry/foundry.toml for settings you use across all projects.Here is an example of a global configuration for connecting to a local Cosmos EVM node:
~/.foundry/foundry.toml
# ~/.foundry/foundry.toml# Declare your named endpoints (optional; for forge test / forking)[rpc_endpoints]cosmos = "<evm_rpc_url>"# Configure the default profile for cast/forge/anvil[profile.default]# Tell Foundry which chain you're targeting:chain_id = 4321# Directly tell cast to use your endpoint:eth_rpc_url = "<evm_rpc_url>"# Set EVM version for Solidity compilationevm_version = "istanbul"
With this global configuration, Foundry tools will automatically connect to your local node without needing additional flags.
When performing testing or development roles you may find yourself doing one or more small but very
tedious tasks frequently.
In your shell’s configuration file (~/.bashrc, ~/.zshrc), you can alias cast with your default RPC URL
(or multiple on various chains) to save time.
# Set your default RPC endpointexport CDEV_RPC="<evm_rpc_url>"# Create an aliasalias ccast='cast --rpc-url $CDEV_RPC'# Now you can run commands like:ccast balance 0x...
This is an extremely basic example of how you can improve your workflows by building upon the heavy lifting Foundry already does out of the box.