diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 84e3bb6e12..f29be08bda 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -125,15 +125,19 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface err := ec.c.CallContext(ctx, &raw, method, args...) if err != nil { return nil, err - } else if len(raw) == 0 { - return nil, ethereum.ErrNotFound } + // Decode header and transactions. var head *types.Header - var body rpcBlock if err := json.Unmarshal(raw, &head); err != nil { return nil, err } + // When the block is not found, the API returns JSON null. + if head == nil { + return nil, ethereum.ErrNotFound + } + + var body rpcBlock if err := json.Unmarshal(raw, &body); err != nil { return nil, err }