Detail how to use the BlockByNumber method when special labels are used

pull/30984/head
EdisonSR 3 weeks ago committed by GitHub
parent ace888b9cf
commit 08a90ad171
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      ethclient/ethclient.go

@ -90,6 +90,12 @@ func (ec *Client) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo
// //
// Note that loading full blocks requires two requests. Use HeaderByNumber // Note that loading full blocks requires two requests. Use HeaderByNumber
// if you don't need all transactions or uncle headers. // if you don't need all transactions or uncle headers.
// if you want to use tag like earliest, latest, finalized, safe, or finalized, you can use the
// UnmarshalJSON fuction to get the corresponding number
// eg:
// var bn rpc.BlockNumber
// err := json.Unmarshal([]byte(`"finalized"`), &bn)
// you will get -3 and you can use for the number param
func (ec *Client) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { func (ec *Client) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
return ec.getBlock(ctx, "eth_getBlockByNumber", toBlockNumArg(number), true) return ec.getBlock(ctx, "eth_getBlockByNumber", toBlockNumArg(number), true)
} }

Loading…
Cancel
Save