Skip to content

Commit

Permalink
Add eth_chainId
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Cichowicz committed Apr 29, 2019
1 parent 698f007 commit c177c18
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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 c177c18

Please sign in to comment.