Skip to content

Commit

Permalink
Add eth_chainId function
Browse files Browse the repository at this point in the history
  • Loading branch information
alisinabh committed Dec 10, 2023
1 parent d0ab816 commit 9d25642
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -129,6 +129,7 @@ $ make test
* [`eth_protocolVersion`](https://eth.wiki/json-rpc/API#eth_protocolversion)
* [`eth_syncing`](https://eth.wiki/json-rpc/API#eth_syncing)
* [`eth_coinbase`](https://eth.wiki/json-rpc/API#eth_coinbase)
* [`eth_chainId`](https://eth.wiki/json-rpc/API#eth_chainId)
* [`eth_mining`](https://eth.wiki/json-rpc/API#eth_mining)
* [`eth_hashrate`](https://eth.wiki/json-rpc/API#eth_hashrate)
* [`eth_gasPrice`](https://eth.wiki/json-rpc/API#eth_gasprice)
Expand Down
5 changes: 5 additions & 0 deletions lib/ethereumex/client/base_client.ex
Expand Up @@ -51,6 +51,11 @@ defmodule Ethereumex.Client.BaseClient do
request("eth_syncing", [], opts)
end

@impl true
def eth_chain_id(opts \\ []) do
request("eth_chainId", [], opts)
end

@impl true
def eth_coinbase(opts \\ []) do
request("eth_coinbase", [], opts)
Expand Down
1 change: 1 addition & 0 deletions lib/ethereumex/client/behaviour.ex
Expand Up @@ -11,6 +11,7 @@ defmodule Ethereumex.Client.Behaviour do
@callback net_listening(keyword()) :: {:ok, boolean()} | error
@callback eth_protocol_version(keyword()) :: {:ok, binary()} | error
@callback eth_syncing(keyword()) :: {:ok, map() | boolean()} | error
@callback eth_chain_id(keyword()) :: {:ok, binary()} | error
@callback eth_coinbase(keyword()) :: {:ok, binary()} | error
@callback eth_mining(keyword()) :: {:ok, boolean()} | error
@callback eth_hashrate(keyword()) :: {:ok, binary()} | error
Expand Down
1 change: 1 addition & 0 deletions test/ethereumex/client/base_client_test.exs
Expand Up @@ -92,6 +92,7 @@ defmodule Ethereumex.Client.BaseClientTest do
test ".eth_protocol_version/0", do: Helpers.check("eth_protocol_version")
test ".eth_syncing/0", do: Helpers.check("eth_syncing")
test ".eth_coinbase/0", do: Helpers.check("eth_coinbase")
test ".eth_chain_id/0", do: Helpers.check("eth_chain_id")
test ".eth_mining/0", do: Helpers.check("eth_mining")
test ".eth_hashrate/0", do: Helpers.check("eth_hashrate")
test ".eth_gas_price/0", do: Helpers.check("eth_gas_price")
Expand Down
9 changes: 9 additions & 0 deletions test/ethereumex/http_client_test.exs
Expand Up @@ -68,6 +68,15 @@ defmodule Ethereumex.HttpClientTest do
end
end

@tag :eth
describe "HttpClient.eth_chain_id/1" do
test "returns chain id of the RPC serveer" do
result = HttpClient.eth_chain_id()

{:ok, <<_::binary>>} = result
end
end

@tag :eth
describe "HttpClient.eth_coinbase/1" do
test "returns coinbase address" do
Expand Down
9 changes: 9 additions & 0 deletions test/ethereumex/ipc_client_test.exs
Expand Up @@ -79,6 +79,15 @@ defmodule Ethereumex.IpcClientTest do
end
end

@tag :eth
describe "IpcClient.eth_chain_id/1" do
test "returns chain id of the RPC serveer" do
result = IpcClient.eth_chain_id()

{:ok, <<_::binary>>} = result
end
end

@tag :eth
describe "IpcClient.eth_coinbase/1" do
test "returns coinbase address" do
Expand Down

0 comments on commit 9d25642

Please sign in to comment.