mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
* ethclient, internal/ethapi: add support for EIP-695 (eth_chainId) #19694 * ethclient: fix typo #23778
This commit is contained in:
parent
aaa42a9a42
commit
917baceda8
2 changed files with 15 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue