Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Added eth_chainId (#419)
Browse files Browse the repository at this point in the history
Fixes #339
  • Loading branch information
tcichowicz authored and davidmurdoch committed Jul 2, 2019
1 parent a0d6d8c commit d458a59
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ The RPC methods currently implemented are:
* [eth_accounts](https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_accounts)
* [eth_blockNumber](https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_blockNumber)
* [eth_call](https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_call)
* `eth_chainId`
* [eth_coinbase](https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_coinbase)
* [eth_estimateGas](https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_estimateGas)
* [eth_gasPrice](https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gasPrice)
Expand Down
5 changes: 5 additions & 0 deletions lib/subproviders/geth_api_double.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ GethApiDouble.prototype.eth_blockNumber = function(callback) {
});
};

GethApiDouble.prototype.eth_chainId = function(callback) {
// chainId of 1337 is the default for private networks as per EIP-155
callback(null, to.hex(1337));
};

GethApiDouble.prototype.eth_coinbase = function(callback) {
callback(null, this.state.coinbase);
};
Expand Down
15 changes: 15 additions & 0 deletions test/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ const tests = function(web3) {
});
});

describe("eth_chainId", function() {
it("should return a default chain id of a private network", async function() {
const send = pify(web3._provider.send.bind(web3._provider));

const result = await send({
id: new Date().getTime(),
jsonrpc: "2.0",
method: "eth_chainId",
params: []
});

assert.strictEqual(result.result, "0x539"); // 0x539 === 1337
});
});

describe("eth_coinbase", function() {
it("should return correct address", async function() {
const coinbase = await web3.eth.getCoinbase();
Expand Down

0 comments on commit d458a59

Please sign in to comment.