Skip to main content
Geth ships with an interactive JavaScript console that exposes the full JSON-RPC API as well as additional management APIs. The console runs a JavaScript runtime (powered by Goja) and connects to the node over RPC.

Starting the console

There are two ways to open a console.

Inline console

Start Geth with a console attached in the same process:
geth console
Combine with other flags as needed:
geth --mainnet console
geth --sepolia console
Geth log output and console output share the same terminal. To suppress log output and keep the console clean, redirect logs to a file:
geth console 2>/tmp/geth.log

Attaching to a running node

If a Geth node is already running, attach a console to it without restarting:
Attaches over the IPC socket. This is the simplest option when you are on the same machine as the node.
geth attach
Specify a non-default socket path:
geth attach /path/to/geth.ipc

Available objects

Once the console is open, the following top-level objects are available, depending on which API namespaces are enabled on the connected node:
ObjectNamespaceDescription
ethethCore Ethereum API
netnetNetwork information
web3web3Utility functions (conversion, hashing)
adminadminNode management
txpooltxpoolTransaction pool inspection
debugdebugLow-level debugging
minerminerMining control (PoW networks only)
Objects are only available when the corresponding namespace is exposed on the RPC endpoint the console is attached to. Over IPC all namespaces are always available.

eth commands

The eth object maps directly to the eth_* JSON-RPC methods.
// Current block number
> eth.blockNumber
12345678

// List accounts in the local keystore
> eth.accounts
["0xd3cda913deb6f4967b2ef3aa68f5a843ffef3dec", "0x..."]

// Get the balance of an address (result is in wei)
> eth.getBalance("0xd3cda913deb6f4967b2ef3aa68f5a843ffef3dec")
1000000000000000000

// Convert wei to ether for readability
> web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")
"1.5"

// Get a transaction receipt by hash
> eth.getTransactionReceipt("0xabcdef1234567890...")
{
  blockHash: "0x...",
  blockNumber: 12345678,
  contractAddress: null,
  gasUsed: 21000,
  status: "0x1",
  transactionHash: "0xabcdef1234567890...",
  ...
}

// Send ETH (requires an unlocked account)
> eth.sendTransaction({
    from: eth.accounts[0],
    to: "0x3535353535353535353535353535353535353535",
    value: web3.toWei("0.5", "ether")
  })
"0x..." // transaction hash

// Get the latest block
> eth.getBlock("latest")
{
  number: 12345678,
  hash: "0x...",
  timestamp: 1680000000,
  transactions: [...],
  ...
}

// Get the current gas price (in wei)
> eth.gasPrice
1000000000

admin commands

The admin namespace provides node management functions.
// Show connected peers
> admin.peers
[{
  id: "04...",
  name: "Geth/v1.x.x-stable/linux-amd64/go1.x.x",
  network: { remoteAddress: "1.2.3.4:30303", ... },
  ...
}]

// Show this node's information (enode, ID, ports)
> admin.nodeInfo
{
  enode: "enode://04...@127.0.0.1:30303",
  id: "...",
  ip: "127.0.0.1",
  listenAddr: "[::]:30303",
  name: "Geth/v1.x.x-stable/linux-amd64/go1.x.x",
  ...
}

// Manually connect to a peer using its enode URL
> admin.addPeer("enode://04...@1.2.3.4:30303")
true

// Show the data directory path
> admin.datadir
"/home/user/.ethereum"

txpool commands

The txpool namespace lets you inspect the local transaction pool.
// Summary count of pending and queued transactions
> txpool.status
{
  pending: 4,
  queued: 1
}

// Full details of all pending and queued transactions
// keyed by sender address and nonce
> txpool.content
{
  pending: {
    "0xd3cda913...": {
      "6": { hash: "0x...", nonce: "0x6", ... }
    }
  },
  queued: { ... }
}

// Same as content, but returns only sender, nonce, and hash
> txpool.inspect

Loading scripts

Run a JavaScript file inside the console with loadScript:
> loadScript("/path/to/script.js")
true
You can also preload scripts when attaching:
geth attach --preload /path/to/init.js,/path/to/helpers.js
To execute a one-off script non-interactively and then exit:
geth --exec 'eth.blockNumber' attach

History and autocomplete

The console stores command history to a file in the Geth data directory (history by default). Use the up and down arrow keys to navigate previous commands. Press Tab to autocomplete object properties and method names. For example, typing eth. and pressing Tab shows all available eth methods.
Use Ctrl+C to cancel the current line and Ctrl+D or type exit to close the console session.

Build docs developers (and LLMs) love