ethclient, internal/ethapi: add support for EIP-695 (eth_chainId) (#19694)

EIP-695 was written in 2017. Parity and Infura have support for this
method and we should, too.
This commit is contained in:
Felix Lange
2019-06-11 13:12:33 +02:00
committed by Péter Szilágyi
parent c420dcb39c
commit 2b54666018
3 changed files with 31 additions and 0 deletions

View File

@ -61,6 +61,16 @@ func (ec *Client) Close() {
// Blockchain Access
// ChainId retrieves the current chain ID for transaction replay protection.
func (ec *Client) ChainID(ctx context.Context) (*big.Int, error) {
var result hexutil.Big
err := ec.c.CallContext(ctx, &result, "eth_chainId")
if err != nil {
return nil, err
}
return (*big.Int)(&result), err
}
// BlockByHash returns the given full block.
//
// Note that loading full blocks requires two requests. Use HeaderByHash