add eth_chainId JSON-RPC endpoint

This commit is contained in:
ramil
2021-04-20 00:52:58 +03:00
parent 9d590e15bc
commit f8b9d9475e
3 changed files with 21 additions and 4 deletions
+13
View File
@@ -167,6 +167,19 @@ func (pea *PublicEthAPI) GetBlockByHash(ctx context.Context, hash common.Hash, f
return nil, err
}
// ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config.
func (api *PublicEthAPI) ChainId() (hexutil.Uint64, error) {
chainID := new(big.Int)
block, err := api.B.CurrentBlock()
if err != nil {
return 0, err
}
if config := api.B.Config.ChainConfig; config.IsEIP155(block.Number()) {
chainID = config.ChainID
}
return (hexutil.Uint64)(chainID.Uint64()), nil
}
/*
Uncles