W3WS.Rpc (w3ws v0.2.0)

W3WS RPC Server

This is useful for making arbitrary requests to the JSON-RPC server over a websocket. This module ignores the id field (if any) in given message as it maintains it's own sequence.

Summary

Functions

Send a message to the RPC server and asynchronously receive the response as a message to the calling process.

Returns a specification to start this module under a supervisor.

Send a message to the RPC server.

Start an RPC server

Stop the RPC server

Types

@type rpc() :: pid()

Functions

Link to this function

async_message(rpc, message)

@spec async_message(rpc(), map()) :: pos_integer()

Send a message to the RPC server and asynchronously receive the response as a message to the calling process.

Examples

receipt = Rpc.async_message(rpc, eth_block_number())

receive do
  {:eth_response, ^receipt, response, _request} -> IO.inspect(response)
end
Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

send_message(rpc, message)

@spec send_message(rpc(), map()) :: {:ok, map()} | {:error, any()}

Send a message to the RPC server.

This is a synchronous function which returns the response from the JSON-RPC server, but does not block the RPC process.

Examples

{:ok, result} = W3WS.Rpc.send_message(rpc, W3WS.Message.eth_block_number())
Link to this function

start_link(args)

@spec start_link([{:uri, String.t()}]) :: {:ok, rpc()}

Start an RPC server

Examples

{:ok, rpc} = W3WS.Rpc.start_link(uri: "ws://localhost:8545")

Stop the RPC server