Quick Reference

Cheatsheets

Practical command references for Linux, networking, servers, containers, databases, and more.

Cheatsheet#ethereum-cli

Ethereum CLI (Geth & Cast) Cheatsheet

Interacting with Ethereum and EVM-compatible chains from the command line is usually done via a node implementation like geth or developer tools like cast (from Foundry).

Go-Ethereum (Geth)

geth is the official Go implementation of the Ethereum protocol.

# Start a full node (Syncs the blockchain)
geth --syncmode "snap"
 
# Attach to a running Geth instance console
geth attach http://127.0.0.1:8545
# Inside console: eth.blockNumber, eth.syncing, net.peerCount
 
# Create a new local account
geth account new
 
# Start Geth with HTTP API enabled (for local development/interaction)
geth --http --http.api "eth,net,web3,personal" --http.corsdomain "*"

Foundry Cast

cast is a Swiss Army knife for interacting with EVM smart contracts, sending transactions, and getting chain data. It is highly recommended over using raw RPC curls.

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

Reading Blockchain Data

# Get the current block number
cast block-number --rpc-url https://eth-mainnet.alchemyapi.io/v2/your-api-key
 
# Get the ETH balance of an address (Returns wei)
cast balance 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
 
# Convert Wei to Ether
cast --from-wei $(cast balance 0xd8dA...) ether

Interacting with Smart Contracts

# Call a read-only function (No gas cost)
cast call <ContractAddress> "balanceOf(address)(uint256)" <TargetAddress> --rpc-url <RPC>
 
# Send a transaction (Mutates state, costs gas)
# Requires providing a private key
cast send <ContractAddress> "transfer(address,uint256)" <TargetAddress> <Amount> \
  --private-key <YourPrivateKey> --rpc-url <RPC>

Utilities

# Convert a string to Hex
cast --from-utf8 "Hello World"
 
# Get the 4-byte function selector signature
cast sig "transfer(address,uint256)"
# Output: 0xa9059cbb