Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public class JsonRpc

  1. Object
  2. JsonRpc

Known subtypesEvmRpc, SolanaRpc

JSON-RPC 2.0 over an RpcTransport: what Ethereum and Solana nodes speak. Parameters and results are the values Json reads and writes: Map, List, String, Boolean, Long, UInt256 and Double.

Constructors

public JsonRpc(RpcTransport transport, String url)A client for an endpoint.

Methods

public String getUrl()The endpoint.
public RpcTransport getTransport()The transport.
public Object call(String method, Object... params) throws IOExceptionCalls a method and answers its result, which may be null.
public Object callWith(String method, Object params) throws IOExceptionCalls a method with a parameter list, or a parameter object when params is a Map.
protected static Map<?, ?> asMap(Object o, String what) throws IOExceptionA result that must be a JSON object.
protected static List<?> asList(Object o, String what) throws IOExceptionA result that must be a JSON array.
protected static String asString(Object o, String what) throws IOExceptionA result that must be a JSON string.
protected static long asLong(Object o, String what) throws IOExceptionA result that must be a JSON integer within long range.

Inherited methods

Constructor details

JsonRpc

public JsonRpc(RpcTransport transport, String url)
A client for an endpoint.

Method details

getUrl

public String getUrl()
The endpoint.

getTransport

public RpcTransport getTransport()
The transport.

call

public Object call(String method, Object... params) throws IOException
Calls a method and answers its result, which may be null.

Throws

RpcException
for an error reply or an HTTP failure
IOException
when the endpoint could not be reached, or answered something that is not a JSON-RPC response

callWith

public Object callWith(String method, Object params) throws IOException
Calls a method with a parameter list, or a parameter object when params is a Map. It is not an overload of call(String, Object...), which would take a single parameter for the whole list.

asMap

protected static Map<?, ?> asMap(Object o, String what) throws IOException
A result that must be a JSON object.

asList

protected static List<?> asList(Object o, String what) throws IOException
A result that must be a JSON array.

asString

protected static String asString(Object o, String what) throws IOException
A result that must be a JSON string.

asLong

protected static long asLong(Object o, String what) throws IOException
A result that must be a JSON integer within long range.