Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Interactive REPL

The ethrex REPL is an interactive Read-Eval-Print Loop for Ethereum JSON-RPC. It lets you query any Ethereum node directly from your terminal using a concise namespace.method syntax.

Quick Start

# Via the ethrex binary
ethrex repl

# Connect to a specific endpoint
ethrex repl -e https://eth.llamarpc.com

# Execute a single command and exit
ethrex repl -x "eth.blockNumber"

CLI Options

ethrex repl [OPTIONS]

Options:
  -e, --endpoint <URL>       JSON-RPC endpoint [default: http://localhost:8545]
      --history-file <PATH>  Path to command history file [default: ~/.ethrex/history]
  -x, --execute <COMMAND>    Execute a single command and exit

RPC Commands

Type namespace.method with arguments separated by spaces or in parentheses:

> eth.blockNumber
68943

> eth.getBalance 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
1000000000000000000

> eth.getBalance("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "latest")
1000000000000000000

> eth.getBlockByNumber 100 true
┌─────────────────────────────────────────┐
│            number   100                 │
│         timestamp   1438270128          │
│  ...                                    │
└─────────────────────────────────────────┘

Supported Namespaces

NamespaceMethodsDescription
eth30Accounts, blocks, transactions, filters, gas, proofs
debug8Raw headers/blocks/transactions/receipts, tracing
admin4Node info, peers, log level, add peer
net2Network ID, peer count
web31Client version
txpool2Transaction pool content and status

Type .help to list all namespaces, .help eth to list methods in a namespace, or .help eth.getBalance for detailed method documentation.

ENS Name Resolution

Any command that accepts an address also accepts ENS names:

> eth.getBalance vitalik.eth
Resolved vitalik.eth -> 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
1000000000000000000

Resolution is done on-chain by querying the ENS registry at 0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e. This works against any endpoint connected to Ethereum mainnet.

Utility Functions

FunctionExampleDescription
toWeitoWei 1.5 ether1500000000000000000Convert to wei
fromWeifromWei 1000000000 gwei1Convert from wei
toHextoHex 2550xffDecimal to hex
fromHexfromHex 0xff255Hex to decimal
keccak256keccak256 0x68656c6c6f0x1c8a...Keccak-256 hash
toChecksumAddresstoChecksumAddress 0xd8da...0xd8dA...EIP-55 checksum
isAddressisAddress 0xd8dA...trueValidate address format

Units for toWei/fromWei: wei, gwei, ether (or eth).

Built-in Commands

CommandDescription
.help [namespace|command]Show help
.exit / .quitExit the REPL
.clearClear the screen
.connect <url>Show or change endpoint
.historyShow history file path

Other Features

  • Tab completion for namespaces, methods, block tags, and utilities
  • Parameter hints shown after typing a full method name
  • Multi-line input — unbalanced {} or [] automatically continues to the next line
  • Persistent history saved to ~/.ethrex/history
  • Formatted output — addresses, hashes, hex quantities, and nested objects are colored and auto-formatted

Using with ethrex dev mode

The REPL pairs well with ethrex dev mode. Start a local node, then connect the REPL to it:

# Terminal 1: start ethrex in dev mode
ethrex --dev

# Terminal 2: connect the REPL (default endpoint is localhost:8545)
ethrex repl

Running from source

# As an ethrex subcommand
cargo run -p ethrex -- repl

# Or directly
cargo run -p ethrex-repl

# Run tests
cargo test -p ethrex-repl