Skip to content

Commit

Permalink
Add eth_chainIdFixes trufflesuite#339
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Cichowicz committed May 21, 2019
1 parent 698f007 commit 23c27a8
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 23c27a8

Please sign in to comment.