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

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

* ethclient: fix typo #23778
This commit is contained in:
Daniel Liu 2025-08-21 13:40:35 +08:00 committed by GitHub
parent aaa42a9a42
commit 917baceda8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View file

@ -63,6 +63,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

View file

@ -306,6 +306,11 @@ func NewBlockChainAPI(b Backend, chainReader consensus.ChainReader) *BlockChainA
}
}
// ChainId returns the chainID value for transaction replay protection.
func (s *BlockChainAPI) ChainId() *hexutil.Big {
return (*hexutil.Big)(s.b.ChainConfig().ChainId)
}
// BlockNumber returns the block number of the chain head.
func (s *BlockChainAPI) BlockNumber() hexutil.Uint64 {
header, _ := s.b.HeaderByNumber(context.Background(), rpc.LatestBlockNumber) // latest header should always be available