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

Added eth_chainId #419

Merged
merged 1 commit into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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