> ## 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.

# primitives/PeerId

> Auto-generated API documentation

[**@tevm/voltaire**](../index.mdx)

***

[@tevm/voltaire](../index.mdx) / primitives/PeerId

# primitives/PeerId

## Type Aliases

### EnodeComponents

> **EnodeComponents** = `object`

Defined in: [src/primitives/PeerId/PeerIdType.ts:23](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/PeerId/PeerIdType.ts#L23)

Parsed enode URL components

#### Properties

##### discoveryPort?

> `readonly` `optional` **discoveryPort**: `number`

Defined in: [src/primitives/PeerId/PeerIdType.ts:31](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/PeerId/PeerIdType.ts#L31)

UDP port for discovery (optional)

##### ip

> `readonly` **ip**: `string`

Defined in: [src/primitives/PeerId/PeerIdType.ts:27](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/PeerId/PeerIdType.ts#L27)

IP address (IPv4 or IPv6)

##### port

> `readonly` **port**: `number`

Defined in: [src/primitives/PeerId/PeerIdType.ts:29](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/PeerId/PeerIdType.ts#L29)

TCP port for RLPx

##### publicKey

> `readonly` **publicKey**: `string`

Defined in: [src/primitives/PeerId/PeerIdType.ts:25](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/PeerId/PeerIdType.ts#L25)

Node public key (128 hex chars)

***

### PeerIdType

> **PeerIdType** = `string` & `object`

Defined in: [src/primitives/PeerId/PeerIdType.ts:18](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/PeerId/PeerIdType.ts#L18)

Branded PeerId type - Ethereum peer identifier
Wraps a string representing a peer ID (typically an enode URL)

Enode URL format: enode://PUBKEY\@IP:PORT?discport=DISCPORT

* PUBKEY: 128 hex character node ID (secp256k1 public key)
* IP: IPv4 or IPv6 address
* PORT: TCP port for RLPx connection
* DISCPORT: (optional) UDP port for peer discovery

#### Type Declaration

##### \[brand]

> `readonly` **\[brand]**: `"PeerId"`

#### Example

```typescript theme={null}
const peerId = "enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@10.3.58.6:30303?discport=30301"
```

## Variables

### PeerId

> `const` **PeerId**: `object`

Defined in: [src/primitives/PeerId/index.ts:31](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/PeerId/index.ts#L31)

#### Type Declaration

##### equals()

> **equals**: (`peerId1`, `peerId2`) => `boolean`

###### Parameters

###### peerId1

`string`

###### peerId2

`string`

###### Returns

`boolean`

##### from()

> **from**: (`value`) => [`PeerIdType`](#peeridtype)

Create PeerId from string

###### Parameters

###### value

`string`

Peer ID string (enode URL or node ID)

###### Returns

[`PeerIdType`](#peeridtype)

Branded peer ID

###### Throws

If value is not a valid peer ID

###### Example

```javascript theme={null}
import * as PeerId from './primitives/PeerId/index.js';
const peerId = PeerId.from("enode://pubkey@192.168.1.1:30303");
```

##### parse()

> **parse**: (`peerId`) => [`EnodeComponents`](#enodecomponents)

###### Parameters

###### peerId

`string`

###### Returns

[`EnodeComponents`](#enodecomponents)

##### toString()

> **toString**: (`peerId`) => `string`

###### Parameters

###### peerId

`string`

###### Returns

`string`

## Functions

### \_equals()

> **\_equals**(`this`, `other`): `boolean`

Defined in: [src/primitives/PeerId/equals.js:16](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/PeerId/equals.js#L16)

Compare two PeerIds for equality

#### Parameters

##### this

[`PeerIdType`](#peeridtype)

##### other

[`PeerIdType`](#peeridtype)

Peer ID to compare

#### Returns

`boolean`

True if equal

#### Example

```javascript theme={null}
import * as PeerId from './primitives/PeerId/index.js';
const a = PeerId.from("enode://abc@192.168.1.1:30303");
const b = PeerId.from("enode://abc@192.168.1.1:30303");
const equal = PeerId._equals.call(a, b); // true
```

***

### \_parse()

> **\_parse**(`this`): [`EnodeComponents`](#enodecomponents)

Defined in: [src/primitives/PeerId/parse.js:21](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/PeerId/parse.js#L21)

Parse enode URL into components

#### Parameters

##### this

[`PeerIdType`](#peeridtype)

#### Returns

[`EnodeComponents`](#enodecomponents)

Parsed enode components

#### Throws

If not a valid enode URL

#### Example

```javascript theme={null}
import * as PeerId from './primitives/PeerId/index.js';
const peerId = PeerId.from("enode://pubkey@192.168.1.1:30303?discport=30301");
const parsed = PeerId._parse.call(peerId);
console.log(parsed.ip);    // "192.168.1.1"
console.log(parsed.port);  // 30303
console.log(parsed.discoveryPort); // 30301
```

***

### \_toString()

> **\_toString**(`this`): `string`

Defined in: [src/primitives/PeerId/toString.js:15](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/PeerId/toString.js#L15)

Convert PeerId to string (identity function for branded type)

#### Parameters

##### this

[`PeerIdType`](#peeridtype)

#### Returns

`string`

Peer ID as string

#### Example

```javascript theme={null}
import * as PeerId from './primitives/PeerId/index.js';
const peerId = PeerId.from("enode://pubkey@192.168.1.1:30303");
const str = PeerId._toString.call(peerId);
```

***

### equals()

> **equals**(`peerId1`, `peerId2`): `boolean`

Defined in: [src/primitives/PeerId/index.ts:19](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/PeerId/index.ts#L19)

#### Parameters

##### peerId1

`string`

##### peerId2

`string`

#### Returns

`boolean`

***

### from()

> **from**(`value`): [`PeerIdType`](#peeridtype)

Defined in: [src/primitives/PeerId/from.js:16](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/PeerId/from.js#L16)

Create PeerId from string

#### Parameters

##### value

`string`

Peer ID string (enode URL or node ID)

#### Returns

[`PeerIdType`](#peeridtype)

Branded peer ID

#### Throws

If value is not a valid peer ID

#### Example

```javascript theme={null}
import * as PeerId from './primitives/PeerId/index.js';
const peerId = PeerId.from("enode://pubkey@192.168.1.1:30303");
```

***

### parse()

> **parse**(`peerId`): [`EnodeComponents`](#enodecomponents)

Defined in: [src/primitives/PeerId/index.ts:23](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/PeerId/index.ts#L23)

#### Parameters

##### peerId

`string`

#### Returns

[`EnodeComponents`](#enodecomponents)

***

### toString()

> **toString**(`peerId`): `string`

Defined in: [src/primitives/PeerId/index.ts:15](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/PeerId/index.ts#L15)

#### Parameters

##### peerId

`string`

#### Returns

`string`
