> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# NodeInfo

> Ethereum node information from admin_nodeInfo RPC

# NodeInfo

Type-safe structure for Ethereum node information returned by `admin_nodeInfo` RPC method.

## Overview

`NodeInfo` represents metadata about a local Ethereum node, including network identity, protocol information, chain state, and listening ports. This data is returned by the `admin_nodeInfo` RPC method available in Geth and compatible clients.

## Quick Start

<Tabs>
  <Tab title="Basic Usage">
    ```typescript theme={null}
    import * as NodeInfo from '@tevm/voltaire/NodeInfo'

    // Parse node info from RPC response
    const nodeInfo = NodeInfo.from({
      enode: "enode://abc123...@192.168.1.1:30303",
      id: "abc123...",
      ip: "192.168.1.1",
      listenAddr: "192.168.1.1:30303",
      name: "Geth/v1.13.0-stable/linux-amd64/go1.21.0",
      ports: {
        discovery: 30303,
        listener: 30303
      },
      protocols: {
        eth: {
          network: 1,
          difficulty: 58750003716598352816469n,
          genesis: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
          head: "0x1234..."
        }
      }
    })

    // Get protocol info
    const ethProtocol = NodeInfo.getProtocol(nodeInfo, "eth")
    console.log(ethProtocol?.network)  // 1
    ```
  </Tab>

  <Tab title="RPC Fetch">
    ```typescript theme={null}
    import * as NodeInfo from '@tevm/voltaire/NodeInfo'

    async function getNodeInfo(rpcUrl: string) {
      const response = await fetch(rpcUrl, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
          jsonrpc: '2.0',
          method: 'admin_nodeInfo',
          params: [],
          id: 1
        })
      })
      const { result } = await response.json()
      return NodeInfo.from(result)
    }

    const nodeInfo = await getNodeInfo('http://localhost:8545')
    console.log(nodeInfo.name)  // "Geth/v1.13.0-stable/..."
    ```
  </Tab>
</Tabs>

## Type Definition

```typescript theme={null}
type NodeInfoType = {
  /** Enode URL of the node */
  readonly enode: PeerIdType
  /** Node ID (hex-encoded public key) */
  readonly id: string
  /** External IP address */
  readonly ip: string
  /** Listen address (IP:PORT) */
  readonly listenAddr: string
  /** Client identifier */
  readonly name: string
  /** Network ports */
  readonly ports: {
    /** UDP discovery port */
    readonly discovery: number
    /** TCP listener port */
    readonly listener: number
  }
  /** Protocol-specific information */
  readonly protocols: {
    /** Ethereum protocol info */
    readonly eth?: {
      readonly network: NetworkIdType
      readonly difficulty: BrandedUint
      readonly genesis: BlockHashType
      readonly head: BlockHashType
      readonly config: Record<string, unknown>
    }
    readonly [protocol: string]: unknown
  }
}
```

## API Reference

### Constructors

```typescript theme={null}
import * as NodeInfo from '@tevm/voltaire/NodeInfo'

// From RPC response object
const nodeInfo = NodeInfo.from(rpcResponse)
```

### Methods

```typescript theme={null}
import * as NodeInfo from '@tevm/voltaire/NodeInfo'

const nodeInfo = NodeInfo.from(data)

// Get protocol-specific information
const ethInfo = NodeInfo.getProtocol(nodeInfo, "eth")
const snapInfo = NodeInfo.getProtocol(nodeInfo, "snap")
```

## Node Properties

### Enode URL

The `enode` field contains the full enode URL for connecting to this node:

```typescript theme={null}
nodeInfo.enode
// "enode://abc123...@192.168.1.1:30303?discport=30301"
```

### Client Name

The `name` field identifies the client software:

```typescript theme={null}
nodeInfo.name
// "Geth/v1.13.0-stable/linux-amd64/go1.21.0"
// "Nethermind/v1.21.0/linux-x64/dotnet7.0.11"
// "Erigon/v2.55.0/linux-amd64/go1.21.0"
```

### Network Ports

```typescript theme={null}
nodeInfo.ports.discovery  // UDP port for peer discovery (default: 30303)
nodeInfo.ports.listener   // TCP port for RLPx connections (default: 30303)
```

### Protocol Information

```typescript theme={null}
const eth = nodeInfo.protocols.eth

eth?.network     // Network ID (1 for mainnet)
eth?.difficulty  // Total chain difficulty
eth?.genesis     // Genesis block hash
eth?.head        // Current head block hash
eth?.config      // Chain configuration
```

## Use Cases

### Node Monitoring

```typescript theme={null}
import * as NodeInfo from '@tevm/voltaire/NodeInfo'

async function monitorNode(rpcUrl: string) {
  const response = await fetch(rpcUrl, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      jsonrpc: '2.0',
      method: 'admin_nodeInfo',
      params: [],
      id: 1
    })
  })
  const { result } = await response.json()
  const nodeInfo = NodeInfo.from(result)

  return {
    client: nodeInfo.name,
    ip: nodeInfo.ip,
    enode: nodeInfo.enode,
    network: nodeInfo.protocols.eth?.network,
    headBlock: nodeInfo.protocols.eth?.head
  }
}
```

### Client Version Check

```typescript theme={null}
import * as NodeInfo from '@tevm/voltaire/NodeInfo'

function parseClientVersion(nodeInfo: NodeInfoType) {
  const name = nodeInfo.name
  const parts = name.split('/')

  return {
    client: parts[0],           // "Geth", "Nethermind", etc.
    version: parts[1],          // "v1.13.0-stable"
    platform: parts[2],         // "linux-amd64"
    runtime: parts[3]           // "go1.21.0"
  }
}

function isGeth(nodeInfo: NodeInfoType): boolean {
  return nodeInfo.name.startsWith('Geth/')
}

function meetsMinVersion(nodeInfo: NodeInfoType, minVersion: string): boolean {
  const version = parseClientVersion(nodeInfo).version
  // Version comparison logic
  return version >= minVersion
}
```

### Multi-Protocol Support Check

```typescript theme={null}
import * as NodeInfo from '@tevm/voltaire/NodeInfo'

function getSupportedProtocols(nodeInfo: NodeInfoType): string[] {
  return Object.keys(nodeInfo.protocols)
}

function supportsSnap(nodeInfo: NodeInfoType): boolean {
  return 'snap' in nodeInfo.protocols
}

function supportsLes(nodeInfo: NodeInfoType): boolean {
  return 'les' in nodeInfo.protocols
}
```

## Related

* [PeerId](/primitives/peer-id) - Enode URL parsing
* [PeerInfo](/primitives/peer-info) - Connected peer information
* [NetworkId](/primitives/network-id) - Network identifiers
* [BlockHash](/primitives/block-hash) - Block hash type

## References

* [Geth admin\_nodeInfo](https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-admin#admin-nodeinfo) - RPC documentation
* [devp2p Protocol](https://github.com/ethereum/devp2p) - Ethereum P2P networking
* [Enode URL Format](https://ethereum.org/en/developers/docs/networking-layer/network-addresses/) - Network addresses
