View Source Signet.Solana.RPC (Signet v1.6.0)

JSON-RPC client for Solana.

Provides typed functions for Solana RPC methods with automatic Base58 encoding of pubkeys, commitment level options, and response deserialization.

Configuration

config :signet,
  solana_node: "https://api.mainnet-beta.solana.com"

Examples

{:ok, balance} = Signet.Solana.RPC.get_balance(pubkey)
{:ok, slot} = Signet.Solana.RPC.get_slot()
{:ok, %{blockhash: bh}} = Signet.Solana.RPC.get_latest_blockhash()

Summary

Functions

Get account info for a pubkey. Returns nil if the account doesn't exist.

Get the SOL balance (in lamports) for an account.

Get the current block height.

Check node health. Returns :ok if healthy, {:error, ...} if unhealthy.

Get the latest blockhash and its last valid block height.

Get the minimum balance for rent exemption for a given data size.

Get account info for multiple pubkeys (max 100).

Get recent prioritization fees. Pass account addresses to see fees for transactions locking those accounts.

Get the statuses of transaction signatures (max 256).

Get the current slot.

Get the token balance for an SPL Token account.

Get all token accounts owned by a wallet.

Get a transaction by its signature.

Get the node version.

Request an airdrop of SOL (devnet/testnet only).

Send a transaction and poll for confirmation.

Send a raw JSON-RPC request to the Solana node.

Send a signed transaction to the network.

Simulate a transaction without submitting it.

Functions

Link to this function

get_account_info(pubkey, opts \\ [])

View Source
@spec get_account_info(
  <<_::256>>,
  keyword()
) :: {:ok, map() | nil} | {:error, term()}

Get account info for a pubkey. Returns nil if the account doesn't exist.

Options

  • :commitment - :processed, :confirmed, or :finalized
  • :encoding - :base64 (default), :base58, :"base64+zstd", :json_parsed
Link to this function

get_balance(pubkey, opts \\ [])

View Source
@spec get_balance(
  <<_::256>>,
  keyword()
) :: {:ok, non_neg_integer()} | {:error, term()}

Get the SOL balance (in lamports) for an account.

Options

  • :commitment - :processed, :confirmed, or :finalized
Link to this function

get_block_height(opts \\ [])

View Source
@spec get_block_height(keyword()) :: {:ok, non_neg_integer()} | {:error, term()}

Get the current block height.

@spec get_health(keyword()) :: :ok | {:error, term()}

Check node health. Returns :ok if healthy, {:error, ...} if unhealthy.

Link to this function

get_latest_blockhash(opts \\ [])

View Source
@spec get_latest_blockhash(keyword()) ::
  {:ok, %{blockhash: binary(), last_valid_block_height: non_neg_integer()}}
  | {:error, term()}

Get the latest blockhash and its last valid block height.

Link to this function

get_minimum_balance_for_rent_exemption(data_length, opts \\ [])

View Source
@spec get_minimum_balance_for_rent_exemption(
  non_neg_integer(),
  keyword()
) :: {:ok, non_neg_integer()} | {:error, term()}

Get the minimum balance for rent exemption for a given data size.

Link to this function

get_multiple_accounts(pubkeys, opts \\ [])

View Source
@spec get_multiple_accounts(
  [<<_::256>>],
  keyword()
) :: {:ok, [map() | nil]} | {:error, term()}

Get account info for multiple pubkeys (max 100).

Options

Link to this function

get_recent_prioritization_fees(addresses \\ [], opts \\ [])

View Source
@spec get_recent_prioritization_fees(
  [<<_::256>>],
  keyword()
) ::
  {:ok, [%{slot: non_neg_integer(), prioritization_fee: non_neg_integer()}]}
  | {:error, term()}

Get recent prioritization fees. Pass account addresses to see fees for transactions locking those accounts.

Link to this function

get_signature_statuses(signatures, opts \\ [])

View Source
@spec get_signature_statuses(
  [String.t()],
  keyword()
) :: {:ok, [map() | nil]} | {:error, term()}

Get the statuses of transaction signatures (max 256).

Options

  • :search_transaction_history - Search beyond recent status cache (default: false)
@spec get_slot(keyword()) :: {:ok, non_neg_integer()} | {:error, term()}

Get the current slot.

Link to this function

get_token_account_balance(pubkey, opts \\ [])

View Source
@spec get_token_account_balance(
  <<_::256>>,
  keyword()
) ::
  {:ok,
   %{
     amount: non_neg_integer(),
     decimals: non_neg_integer(),
     ui_amount_string: String.t()
   }}
  | {:error, term()}

Get the token balance for an SPL Token account.

Returns the raw integer amount, decimal precision, and ui_amount_string (a human-readable formatted string provided by the RPC node, e.g. "1.5" for 1500000 with 6 decimals).

Link to this function

get_token_accounts_by_owner(owner, filter, opts \\ [])

View Source
@spec get_token_accounts_by_owner(<<_::256>>, keyword(), keyword()) ::
  {:ok, [%{pubkey: String.t(), account: map()}]} | {:error, term()}

Get all token accounts owned by a wallet.

Requires exactly one filter: :mint (specific token) or :program_id (all tokens under a program).

Uses jsonParsed encoding by default for structured token account data.

Examples

get_token_accounts_by_owner(wallet, mint: usdc_mint)
get_token_accounts_by_owner(wallet, program_id: Programs.token_program())
Link to this function

get_transaction(signature, opts \\ [])

View Source
@spec get_transaction(
  String.t(),
  keyword()
) :: {:ok, map() | nil} | {:error, term()}

Get a transaction by its signature.

Returns nil if the transaction is not found.

Options

  • :commitment - :confirmed or :finalized (:processed is NOT supported)
  • :encoding - :json (default), :json_parsed, :base64, :base58
@spec get_version(keyword()) ::
  {:ok, %{solana_core: String.t(), feature_set: non_neg_integer()}}
  | {:error, term()}

Get the node version.

Link to this function

request_airdrop(pubkey, lamports, opts \\ [])

View Source
@spec request_airdrop(<<_::256>>, non_neg_integer(), keyword()) ::
  {:ok, String.t()} | {:error, term()}

Request an airdrop of SOL (devnet/testnet only).

Returns the airdrop transaction signature.

Link to this function

send_and_confirm(transaction, opts \\ [])

View Source
@spec send_and_confirm(
  Signet.Solana.Transaction.t() | binary(),
  keyword()
) :: {:ok, String.t()} | {:error, term()}

Send a transaction and poll for confirmation.

Options

  • :commitment - Confirmation level to wait for (default: :confirmed)
  • :timeout - Max time to wait in ms (default: 30_000)
  • :poll_interval - Poll interval in ms (default: 500)
  • All options from send_transaction/2
Link to this function

send_rpc(method, params, opts \\ [])

View Source
@spec send_rpc(String.t(), list(), keyword()) :: {:ok, term()} | {:error, term()}

Send a raw JSON-RPC request to the Solana node.

Options:

  • :solana_node - Override the node URL
  • :timeout - Request timeout in ms (default: 30000)
  • :id - JSON-RPC request ID (default: auto-generated)

Examples

Signet.Solana.RPC.send_rpc("getSlot", [])
{:ok, 123456789}
Link to this function

send_transaction(transaction, opts \\ [])

View Source
@spec send_transaction(
  binary() | Signet.Solana.Transaction.t(),
  keyword()
) :: {:ok, String.t()} | {:error, term()}

Send a signed transaction to the network.

Accepts a Signet.Solana.Transaction struct or raw serialized bytes.

Options

  • :encoding - :base64 (default) or :base58
  • :skip_preflight - Skip preflight checks (default: false)
  • :preflight_commitment - Commitment for preflight simulation
  • :max_retries - Max retries before giving up

Returns the transaction signature (Base58 string).

Link to this function

simulate_transaction(transaction, opts \\ [])

View Source
@spec simulate_transaction(
  binary() | Signet.Solana.Transaction.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Simulate a transaction without submitting it.

Returns simulation result including logs, compute units consumed, and errors.