From f5ff022dbca2b14af59974154874537b5ed4cc5e Mon Sep 17 00:00:00 2001 From: Felipe Strozberg <48066928+FelStroz@users.noreply.github.com> Date: Wed, 11 May 2022 02:05:55 -0300 Subject: [PATCH] ethclient: add PeerCount method (#24849) * adding peer count function * Update ethclient.go Co-authored-by: Felix Lange --- ethclient/ethclient.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 68389efbf..24edd8648 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -94,6 +94,13 @@ func (ec *Client) BlockNumber(ctx context.Context) (uint64, error) { return uint64(result), err } +// PeerCount returns the number of p2p peers as reported by the net_peerCount method. +func (ec *Client) PeerCount(ctx context.Context) (uint64, error) { + var result hexutil.Uint64 + err := ec.c.CallContext(ctx, &result, "net_peerCount") + return uint64(result), err +} + type rpcBlock struct { Hash common.Hash `json:"hash"` Transactions []rpcTransaction `json:"transactions"`