SolanaRpcClient and send these RPC requests.
Add dependencies
Therpc-core library provides a convenient SolanaRpcClient that implements an API to call these RPC methods and return responses.
build.gradle.kts
Create an RPC Client
To create an instance of aSolanaRpcClient, pass in:
- an RPC
urlthat the client will send requests. - a
networkDriverused to send HTTP requests.
Example: Fetching latest blockhash
Calling thegetLatestBlockhash method returns an RpcResponse.
-
If successful, the response result will contain a
BlockhashResult. -
If an error occured, the response will contain an
RpcError.
Example: Sending a transaction
To submit a transaction to the RPC, use thesendTransaction method.
- If successful, the response result will contain a transaction signature string.
-
If an error occured, the response will contain an
RpcError.
Next steps
These examples are just some of the methods supported bySolanaRpcClient. Here are suggestions to continue learning:
- Read the following guide to learn how to build Solana program instructions and transactions.
- For a complete reference of the RPC methods supported, view the
SolanaRpcClientsource code and unit tests. - Read the Building JSON RPC requests deep dive to learn how to create requests for RPC methods that aren’t immediately supported by
SolanaRpcClient.
Code samples on this page are subject to the Apache 2.0 license.
