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
- Object
- JsonRpc
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
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 IOExceptionCalls a method and answers its
result, which may be null.Throws
RpcException- for an
errorreply 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 IOExceptionCalls 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.Throws
asMap
protected static Map<?, ?> asMap(Object o, String what)
throws IOExceptionA result that must be a JSON object.
Throws
asList
protected static List<?> asList(Object o, String what)
throws IOExceptionA result that must be a JSON array.
Throws
asString
protected static String asString(Object o, String what)
throws IOExceptionA result that must be a JSON string.
Throws
asLong
protected static long asLong(Object o, String what)
throws IOExceptionA result that must be a JSON integer within
long range.