Add dependencies
Therpc-core library provides core classes and abstractions to build and submit requests according to the JSON-RPC 2.0 specification.
Creating a JSON RPC Request
Therpc-core library defines a JsonRpc20Request constructor to conveniently construct a Solana JSON RPC request.
Populate the JSON object with the method name and JSON serialized parameters of a Solana RPC method. The
constructor also includes a requestId parameter, as per JSON-RPC spec.
Example: getLatestBlockhash RPC request
Defining the JSON RPC Response
After creating the request, create Kotlin serializable classes that define the expected response payload for that request. In the following example, we are defining the expected response of thegetLatestBlockhash request using the kotlinx.serialization library.
Example: getLatestBlockhash RPC response
Implement HttpNetworkDriver
The rpc-core library defines a HttpNetworkDriver interface that is used to make network requests.
makeHttpRequest method. The following
is an example from the Kotlin Jetpack Compose Scaffold sample app.
Sending RPC requests
After putting these parts together, use theRpc20Driver class to point to an RPC uri, send
the request, and receive a response.
Next steps
- Browse the full list of Solana RPC HTTP Methods
