Skip to content

Node Endpoints

beacon_client.node_endpoints.NodeEndpoints

Source code in beacon_client/node_endpoints.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
class NodeEndpoints:
    def get_node_identity(self) -> NetworkIdentity:
        """
        Retrieves data about the node's network presence
        """
        value = self._query_url("/eth/v1/node/identity")
        data = parse_json(value["data"], NetworkIdentity)
        return data

    def get_node_peers(
        self,
        disconnected: bool = False,
        disconnecting: bool = False,
        connected: bool = False,
        connecting: bool = False,
        inbound: bool = False,
        outbound: bool = False,
    ) -> List[PeerDescription]:
        """
        Retrieves data about the node's network peers.
        By default this returns all peers.
        Multiple query params are combined using AND conditions
        Args:
            disconnected: If true return nodes with status disconnected
            disconnecting: If true return nodes with status disconnecting
            connected: If true return nodes with status connected
            connecting: If true return nodes with status connecting
            inbound: If true return nodes with direction inbound
            outbound: If true return nodes with direction outbound
        """
        state = []
        direction = []
        if disconnected:
            state.append("disconnected")
        if disconnecting:
            state.append("disconnecting")
        if connected:
            state.append("connected")
        if connecting:
            state.append("connecting")
        if inbound:
            direction.append("inbound")
        if outbound:
            direction.append("outbound")
        assert (
            len(state) > 0
        ), "Must request at least one state in [disconnected, disconnecting, connected, connecting]"
        assert (
            len(direction) > 0
        ), "Must request at least one direction in [inbound, outbound]"
        params = {"state": state, "direction": direction}
        value = self._query_url("/eth/v1/node/peers", params=params)
        data = parse_json(value["data"], PeerDescription)
        return data

    def get_peer_by_id(self, peer_id: PeerId) -> PeerDescription:
        """
        Retrieves data about the given peer
        Args:
            peer_id: Return peer for given peer id
        """
        value = self._query_url(f"/eth/v1/node/peers/{peer_id}")
        data = parse_json(value["data"], PeerDescription)
        return data

    def get_peer_count(self) -> PeerSummary:
        """
        Retrieves number of known peers.
        """
        value = self._query_url("/eth/v1/node/peer_count")
        data = parse_json(value["data"], PeerSummary)
        return data

    def get_node_version(self) -> str:
        """
        Requests that the beacon node identify information about its implementation in a format similar to a HTTP User-Agent field.
        """
        return self._query_url("/eth/v1/node/version")["data"]["version"]

    def get_syncing_status(self) -> SyncStatus:
        """
        Requests the beacon node to describe if it's currently syncing or not, and if it is, what block it is up to.
        """
        value = self._query_url("/eth/v1/node/syncing")
        data = parse_json(value["data"], SyncStatus)
        return data

get_node_identity()

Retrieves data about the node's network presence

Source code in beacon_client/node_endpoints.py
 7
 8
 9
10
11
12
13
def get_node_identity(self) -> NetworkIdentity:
    """
    Retrieves data about the node's network presence
    """
    value = self._query_url("/eth/v1/node/identity")
    data = parse_json(value["data"], NetworkIdentity)
    return data

get_node_peers(disconnected=False, disconnecting=False, connected=False, connecting=False, inbound=False, outbound=False)

Retrieves data about the node's network peers. By default this returns all peers. Multiple query params are combined using AND conditions

Parameters:

Name Type Description Default
disconnected bool

If true return nodes with status disconnected

False
disconnecting bool

If true return nodes with status disconnecting

False
connected bool

If true return nodes with status connected

False
connecting bool

If true return nodes with status connecting

False
inbound bool

If true return nodes with direction inbound

False
outbound bool

If true return nodes with direction outbound

False
Source code in beacon_client/node_endpoints.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def get_node_peers(
    self,
    disconnected: bool = False,
    disconnecting: bool = False,
    connected: bool = False,
    connecting: bool = False,
    inbound: bool = False,
    outbound: bool = False,
) -> List[PeerDescription]:
    """
    Retrieves data about the node's network peers.
    By default this returns all peers.
    Multiple query params are combined using AND conditions
    Args:
        disconnected: If true return nodes with status disconnected
        disconnecting: If true return nodes with status disconnecting
        connected: If true return nodes with status connected
        connecting: If true return nodes with status connecting
        inbound: If true return nodes with direction inbound
        outbound: If true return nodes with direction outbound
    """
    state = []
    direction = []
    if disconnected:
        state.append("disconnected")
    if disconnecting:
        state.append("disconnecting")
    if connected:
        state.append("connected")
    if connecting:
        state.append("connecting")
    if inbound:
        direction.append("inbound")
    if outbound:
        direction.append("outbound")
    assert (
        len(state) > 0
    ), "Must request at least one state in [disconnected, disconnecting, connected, connecting]"
    assert (
        len(direction) > 0
    ), "Must request at least one direction in [inbound, outbound]"
    params = {"state": state, "direction": direction}
    value = self._query_url("/eth/v1/node/peers", params=params)
    data = parse_json(value["data"], PeerDescription)
    return data

get_node_version()

Requests that the beacon node identify information about its implementation in a format similar to a HTTP User-Agent field.

Source code in beacon_client/node_endpoints.py
79
80
81
82
83
def get_node_version(self) -> str:
    """
    Requests that the beacon node identify information about its implementation in a format similar to a HTTP User-Agent field.
    """
    return self._query_url("/eth/v1/node/version")["data"]["version"]

get_peer_by_id(peer_id)

Retrieves data about the given peer

Parameters:

Name Type Description Default
peer_id PeerId

Return peer for given peer id

required
Source code in beacon_client/node_endpoints.py
61
62
63
64
65
66
67
68
69
def get_peer_by_id(self, peer_id: PeerId) -> PeerDescription:
    """
    Retrieves data about the given peer
    Args:
        peer_id: Return peer for given peer id
    """
    value = self._query_url(f"/eth/v1/node/peers/{peer_id}")
    data = parse_json(value["data"], PeerDescription)
    return data

get_peer_count()

Retrieves number of known peers.

Source code in beacon_client/node_endpoints.py
71
72
73
74
75
76
77
def get_peer_count(self) -> PeerSummary:
    """
    Retrieves number of known peers.
    """
    value = self._query_url("/eth/v1/node/peer_count")
    data = parse_json(value["data"], PeerSummary)
    return data

get_syncing_status()

Requests the beacon node to describe if it's currently syncing or not, and if it is, what block it is up to.

Source code in beacon_client/node_endpoints.py
85
86
87
88
89
90
91
def get_syncing_status(self) -> SyncStatus:
    """
    Requests the beacon node to describe if it's currently syncing or not, and if it is, what block it is up to.
    """
    value = self._query_url("/eth/v1/node/syncing")
    data = parse_json(value["data"], SyncStatus)
    return data