githubEdit

Ethereum

Interact with Ethereum using Foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.

Setup Foundry

Please refer to the Foundry's repositoryarrow-up-right for details. To install foundryup, run the following command to install foundry toolchain.

curl -L https://foundry.paradigm.xyz | bash
foundryup

We can set the environment variable for Ethereum RPC URL to interact the Ethereum blockchain so that we don’t need to set the RPC url flag when running each command.

export ETH_RPC_URL="http://10.0.0.1:12345/path/to/rpc"

Investigating a Chain

cast command of Foundry performs Ethereum RPC calls.

# Get the Ethereum chain id
cast chain-id
# Get the symbolic name of the current chain
cast chain
# Get the current client version
cast client

# Get the current gas price
cast gas-price

# Get the latest block number
cast block-number
# Get information about a block
cast block

Investigating Account

Investigating Contract

Call Functions

If we know the functions of a target contract, we can simply call them. Note that these command do NOT send transactions, so cannot change states or values in the contract.

Send Transactions

We can interact with the contract that is already deployed in Ethereum chain if we have the private key of the account and the contract address.

If we got error like unsupported feature: eip1559 , add --legacy flag for the command.

Last updated