ethclient: add BlockNumber method (#21500)

This adds a new client method BlockNumber to fetch the most recent
block number of the chain.
pull/21549/head
Dan Sosedoff 4 years ago committed by GitHub
parent 4ea9737de6
commit 1167639524
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      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"`

Loading…
Cancel
Save