Connecting RPCS
Contacting the Solana blockchain via an RPC is an important part of any decentralized application. Umi provides a RpcInterface that helps us do just that.
Configuring the RPC's endpoint
When creating a new Umi instance via the default bundle, you must pass the RPC's endpoint or an instance of @solana/web3.js
's Connection
class as the first argument. Going forward, this is the endpoint or Connection
that will be used every time you call a method on the RPC interface.
Alternatively, you may set or update the RPC implementation explicitly by the using the plugin they provide. For instance, the web3JsRpc
plugin will set the RPC implementation to use the @solana/web3.js
library.
Getting the RPC's endpoint and cluster
Once an RPC implementation has been set, you may access its endpoint and cluster via the following methods:
Where cluster
is one of the following:
Sending transactions
The following methods can be used to send, confirm and fetch transactions:
Since transactions are an important component of Solana clients, we discuss them in more detail on the Sending transactions documentation page.
Fetching accounts
The following methods can be used to fetch accounts or check for their existence:
Since fetching accounts is one of the most common operations, we discuss it in more detail on the Fetching accounts documentation page.
Airdropping SOL on supported clusters
If the used cluster supports airdrops, you can use the following method to send SOL to an account and confirm the request.
Getting the balance of an account
You may use the following method to get the SOL balance of any account. This will return a SolAmount
object as documented here.
Getting the latest blockhash
You may get the latest blockhash with its expiry block height via the following method:
Getting the most recent slot
You may get the most recent slot as a number via the following method:
Getting the rent exemption
If you need to figure out the storage fees for an account, you may use the getRent
method and pass in the amount bytes that the account's data will require. This will return the rent-exemption fee — a.k.a storage fee — as a SolAmount
.
Note that this will automatically take the size of the account header into consideration so you only need to pass in the bytes of the account's data.
Say you now wanted to get the rent-exemption fee for 3 accounts with 100 bytes of data each. Running umi.rpc.getRent(100 * 3)
will not provide an accurate response since it will only add the account header for one account and not three. This is why Umi allows you to pass in the account header size explicitly by setting the includesHeaderBytes
option to true
.
Sending custom RPC requests
Because each RPC endpoint may provide their own custom methods, Umi allows you to send custom requests to the RPC via the call
method. It takes the method name as the first argument and an optional array of parameters as the second argument.
Last updated