Manage Peers
Pre-requirements
Before you can create add and retrieve peers, you will need to:
Add Peers
You can add peers using the
SingleNodeClient.peerAdd(multiAddress, alias?) function.
You will need to provide a multiAddress
and, optionally, and alias.
Retrieve Peers
You can retrieve a SingleNodeClient's peers using the
SingleNodeClient.peers() function. The peers()
function
will return a list of peers.
Retrieve Peer Data
Once you have retrieved your node's peers, you can use any of its properties to retrieve the peer's data.
Delete Peers
You can delete a SingleNodeClient's peer using the
SingleNodeClient.peerDelete(peerId) function. You will
need to provide a valid peerId
.
Example Code
stardust/packages/iota/examples/peers/src/index.ts
loading...
Expected Output
Peers
Id: 12D3KooWNSCD7hha6BTPw44XeeKXcrAPBUGnPAY55gvXPen6zEAk
Multi Address: ['/ip4/217.251.138.169/tcp/15600']
Alias: undefined
Relation: autopeered
Connected: true
Gossip Heartbeat
Latest Milestone Index: 71452
Pruned Milestone Index: 55600
Solid Milestone Index: 71452
Connected Peers: 3
Synced Peers: 3
Gossip Metrics
New Blocks: 4282
Known Blocks: 6
Received Blocks: 4291
Received Block Requests: 0
Received Milestone Requests: 1
Received Hearbeats: 241
Sent Blocks: 22
Sent Block Requests: 6
Sent Milestone Requests: 1
Sent Heartbeats: 241
Dropped Packets: 0