From 51dd117a3423504c12c16e23834d97a45f1b5359 Mon Sep 17 00:00:00 2001 From: ia Date: Fri, 18 Aug 2017 07:45:43 -0500 Subject: [PATCH] eth,internal: add eth_chainId method to PublicEthereumApi JSONRPC --- eth/api.go | 5 +++++ internal/web3ext/web3ext.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/eth/api.go b/eth/api.go index 708f75a784..7bb6847b49 100644 --- a/eth/api.go +++ b/eth/api.go @@ -67,6 +67,11 @@ func (api *PublicEthereumAPI) Hashrate() hexutil.Uint64 { return hexutil.Uint64(api.e.Miner().HashRate()) } +// ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config. +func (api *PublicEthereumAPI) ChainId() *big.Int { + return api.e.chainConfig.ChainId +} + // PublicMinerAPI provides an API to control the miner. // It offers only methods that operate on data that pose no security risk when it is publicly accessible. type PublicMinerAPI struct { diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index f4eb47a12a..bf4b7808f7 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -433,6 +433,11 @@ const Eth_JS = ` web3._extend({ property: 'eth', methods: [ + new web3._extend.Method({ + name: 'chainId', + call: 'eth_chainId', + params: 0 + }), new web3._extend.Method({ name: 'sign', call: 'eth_sign',