From 116763952498d9c1b852fa94542df1b3f03e2812 Mon Sep 17 00:00:00 2001 From: Dan Sosedoff Date: Thu, 10 Sep 2020 07:24:21 -0500 Subject: [PATCH] ethclient: add BlockNumber method (#21500) This adds a new client method BlockNumber to fetch the most recent block number of the chain. --- ethclient/ethclient.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index bc0305fc22..a964bd0f8d 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -88,6 +88,13 @@ func (ec *Client) BlockByNumber(ctx context.Context, number *big.Int) (*types.Bl return ec.getBlock(ctx, "eth_getBlockByNumber", toBlockNumArg(number), true) } +// BlockNumber returns the most recent block number +func (ec *Client) BlockNumber(ctx context.Context) (uint64, error) { + var result hexutil.Uint64 + err := ec.c.CallContext(ctx, &result, "eth_getBlockNumber", nil) + return uint64(result), err +} + type rpcBlock struct { Hash common.Hash `json:"hash"` Transactions []rpcTransaction `json:"transactions"`