Documentation
¶
Overview ¶
Package rpc provides the typed Solana JSON-RPC client. It embeds a jsonrpc.Client transport and exposes Solana-specific methods (GetAccountInfo, SendTransaction, …). For raw JSON-RPC transport only — without the Solana method surface — use the jsonrpc package directly.
WebSocket subscriptions live in the ws package; attach a *ws.Client to a *Client via WithWebSocket when you need both RPC and WS on one logical client.
Index ¶
- Constants
- func DecodeTransactionError(raw any) error
- func FirstOrZero[T any](opts []T) *T
- type AccountInfoCfg
- type BlockCommitment
- type BlockProductionRange
- type BlockProductionResult
- type BlockProductionValue
- type BlockTransaction
- type Client
- func (c *Client) GetAccountInfo(ctx context.Context, pubkey solana.PublicKey, cfg ...AccountInfoCfg) (*GetAccountInfoResult, error)
- func (c *Client) GetAddressLookupTable(ctx context.Context, address solana.PublicKey, cfg ...CommitmentWithMinSlotCfg) (*GetAddressLookupTableResult, error)
- func (c *Client) GetBalance(ctx context.Context, pubkey solana.PublicKey, cfg ...CommitmentWithMinSlotCfg) (*GetBalanceResult, error)
- func (c *Client) GetBlock(ctx context.Context, slot uint64, cfg ...GetBlockCfg) (*GetBlockResult, error)
- func (c *Client) GetBlockCommitment(ctx context.Context, slot uint64) (*BlockCommitment, error)
- func (c *Client) GetBlockHeight(ctx context.Context, cfg ...CommitmentWithMinSlotCfg) (uint64, error)
- func (c *Client) GetBlockProduction(ctx context.Context, cfg ...CommitmentCfg) (*BlockProductionResult, error)
- func (c *Client) GetBlockTime(ctx context.Context, slot uint64) (*int64, error)
- func (c *Client) GetBlocks(ctx context.Context, start uint64, end *uint64, cfg ...CommitmentCfg) ([]uint64, error)
- func (c *Client) GetBlocksWithLimit(ctx context.Context, startSlot uint64, limit uint64, cfg ...CommitmentCfg) ([]uint64, error)
- func (c *Client) GetClusterNodes(ctx context.Context) ([]ClusterNode, error)
- func (c *Client) GetEpochInfo(ctx context.Context, cfg ...CommitmentWithMinSlotCfg) (*EpochInfo, error)
- func (c *Client) GetEpochSchedule(ctx context.Context) (*EpochSchedule, error)
- func (c *Client) GetFeeForMessage(ctx context.Context, msg *solana.Message, cfg ...CommitmentWithMinSlotCfg) (*GetFeeForMessageResult, error)
- func (c *Client) GetFirstAvailableBlock(ctx context.Context) (uint64, error)
- func (c *Client) GetGenesisHash(ctx context.Context) (solana.Hash, error)
- func (c *Client) GetHealth(ctx context.Context) (string, error)
- func (c *Client) GetHighestSnapshotSlot(ctx context.Context) (*HighestSnapshotSlot, error)
- func (c *Client) GetIdentity(ctx context.Context) (solana.PublicKey, error)
- func (c *Client) GetInflationGovernor(ctx context.Context, cfg ...CommitmentCfg) (*InflationGovernor, error)
- func (c *Client) GetInflationRate(ctx context.Context) (*InflationRate, error)
- func (c *Client) GetInflationReward(ctx context.Context, addresses []solana.PublicKey, cfg ...InflationRewardCfg) ([]*InflationReward, error)
- func (c *Client) GetLargestAccounts(ctx context.Context, cfg ...LargestAccountsCfg) ([]LargestAccount, error)
- func (c *Client) GetLatestBlockhash(ctx context.Context, cfg ...CommitmentWithMinSlotCfg) (*LatestBlockhash, error)
- func (c *Client) GetLeaderSchedule(ctx context.Context, slot *uint64, cfg ...LeaderScheduleCfg) (map[string][]uint64, error)
- func (c *Client) GetMaxRetransmitSlot(ctx context.Context) (uint64, error)
- func (c *Client) GetMaxShredInsertSlot(ctx context.Context) (uint64, error)
- func (c *Client) GetMinimumBalanceForRentExemption(ctx context.Context, dataSize uint64, cfg ...CommitmentCfg) (uint64, error)
- func (c *Client) GetMultipleAccounts(ctx context.Context, addresses []solana.PublicKey, cfg ...AccountInfoCfg) (*GetMultipleAccountsResult, error)
- func (c *Client) GetProgramAccounts(ctx context.Context, program solana.PublicKey, cfg ...AccountInfoCfg) ([]ProgramAccount, error)
- func (c *Client) GetRecentPerformanceSamples(ctx context.Context, limit *uint64) ([]PerformanceSample, error)
- func (c *Client) GetRecentPrioritizationFees(ctx context.Context, addresses []solana.PublicKey) ([]PrioritizationFee, error)
- func (c *Client) GetSignatureStatuses(ctx context.Context, sigs []solana.Signature, cfg ...SignatureStatusesCfg) (*GetSignatureStatusesResult, error)
- func (c *Client) GetSignaturesForAddress(ctx context.Context, addr solana.PublicKey, cfg ...SignaturesForAddressCfg) ([]*ConfirmedSignatureForAddress, error)
- func (c *Client) GetSlot(ctx context.Context, cfg ...CommitmentWithMinSlotCfg) (uint64, error)
- func (c *Client) GetSlotLeader(ctx context.Context, cfg ...CommitmentWithMinSlotCfg) (solana.PublicKey, error)
- func (c *Client) GetSlotLeaders(ctx context.Context, startSlot uint64, limit uint64) ([]solana.PublicKey, error)
- func (c *Client) GetStakeActivation(ctx context.Context, account solana.PublicKey, cfg ...CommitmentWithMinSlotCfg) (*StakeActivation, error)
- func (c *Client) GetStakeMinimumDelegation(ctx context.Context, cfg ...CommitmentCfg) (uint64, error)
- func (c *Client) GetSupply(ctx context.Context, cfg ...CommitmentCfg) (*SupplyResult, error)
- func (c *Client) GetTokenAccountBalance(ctx context.Context, account solana.PublicKey, cfg ...CommitmentCfg) (*GetTokenAccountBalanceResult, error)
- func (c *Client) GetTokenAccountsByDelegate(ctx context.Context, delegate solana.PublicKey, filter TokenAccountFilter, ...) ([]TokenAccount, error)
- func (c *Client) GetTokenAccountsByOwner(ctx context.Context, owner solana.PublicKey, filter TokenAccountFilter, ...) ([]TokenAccount, error)
- func (c *Client) GetTokenLargestAccounts(ctx context.Context, mint solana.PublicKey, cfg ...CommitmentCfg) ([]TokenLargestAccount, error)
- func (c *Client) GetTokenSupply(ctx context.Context, mint solana.PublicKey, cfg ...CommitmentCfg) (*GetTokenSupplyResult, error)
- func (c *Client) GetTransaction(ctx context.Context, sig solana.Signature, cfg ...GetTransactionCfg) (*GetTransactionResult, error)
- func (c *Client) GetTransactionCount(ctx context.Context, cfg ...CommitmentWithMinSlotCfg) (uint64, error)
- func (c *Client) GetVersion(ctx context.Context) (*SolanaVersion, error)
- func (c *Client) GetVoteAccounts(ctx context.Context, cfg ...CommitmentCfg) (*VoteAccounts, error)
- func (c *Client) IsBlockhashValid(ctx context.Context, blockhash solana.Hash, cfg ...CommitmentWithMinSlotCfg) (bool, error)
- func (c *Client) MinimumLedgerSlot(ctx context.Context) (uint64, error)
- func (c *Client) RequestAirdrop(ctx context.Context, pubkey solana.PublicKey, lamports uint64, ...) (solana.Signature, error)
- func (c *Client) SendAndConfirmSignedTransaction(ctx context.Context, tx *solana.Transaction, opts ...SendAndConfirmOption) (solana.Signature, error)
- func (c *Client) SendAndConfirmTransaction(ctx context.Context, build TransactionBuilder, opts ...SendAndConfirmOption) (solana.Signature, error)
- func (c *Client) SendRawTransaction(ctx context.Context, raw []byte, cfg ...SendTxCfg) (solana.Signature, error)
- func (c *Client) SendTransaction(ctx context.Context, tx *solana.Transaction, cfg ...SendTxCfg) (solana.Signature, error)
- func (c *Client) SimulateTransaction(ctx context.Context, tx *solana.Transaction, cfg ...SimulateTxCfg) (*SimulateResult, error)
- func (c *Client) Transport() *jsonrpc.Client
- type ClusterNode
- type CommitmentCfg
- type CommitmentWithEncodingCfg
- type CommitmentWithMinSlotCfg
- type ConfirmedSignatureForAddress
- type DataSlice
- type EpochInfo
- type EpochSchedule
- type GetAccountInfoResult
- type GetAddressLookupTableResult
- type GetBalanceResult
- type GetBlockCfg
- type GetBlockResult
- type GetFeeForMessageResult
- type GetMultipleAccountsResult
- type GetSignatureStatusesResult
- type GetTokenAccountBalanceResult
- type GetTokenSupplyResult
- type GetTransactionCfg
- type GetTransactionResult
- type HighestSnapshotSlot
- type InflationGovernor
- type InflationRate
- type InflationReward
- type InflationRewardCfg
- type InstructionError
- type LargestAccount
- type LargestAccountsCfg
- type LatestBlockhash
- type LeaderScheduleCfg
- type LogsSubscribeCfg
- type PerformanceSample
- type PrioritizationFee
- type ProgramAccount
- type SendAndConfirmOption
- func WithConfirmTimeout(d time.Duration) SendAndConfirmOption
- func WithMaxBlockhashRetries(n int) SendAndConfirmOption
- func WithPollInterval(d time.Duration) SendAndConfirmOption
- func WithSendCommitment(c solana.CommitmentLevel) SendAndConfirmOption
- func WithSendSkipPreflight(b bool) SendAndConfirmOption
- type SendTxCfg
- type SignatureStatus
- type SignatureStatusesCfg
- type SignatureSubscribeCfg
- type SignaturesForAddressCfg
- type SimulateResult
- type SimulateTxCfg
- type SimulationReturnData
- type SolanaVersion
- type StakeActivation
- type SupplyResult
- type TokenAccount
- type TokenAccountFilter
- type TokenAmount
- type TokenLargestAccount
- type TransactionBuilder
- type TransactionError
- type TransactionMeta
- type VoteAccount
- type VoteAccounts
Constants ¶
const MaxGetMultipleAccountsAddresses = 100
MaxGetMultipleAccountsAddresses is the per-request limit the Solana RPC server enforces on getMultipleAccounts. The SDK validates input length up-front so callers get a precise error instead of a vague "Invalid params" from the server.
const MaxGetRecentPrioritizationFeesAddresses = 128
MaxGetRecentPrioritizationFeesAddresses is the per-request limit the Solana RPC server enforces on getRecentPrioritizationFees.
const MaxGetSignatureStatusesSignatures = 256
MaxGetSignatureStatusesSignatures is the per-request limit the Solana RPC server enforces on getSignatureStatuses. The SDK validates input length up-front so callers get a precise error instead of a vague "Invalid params" from the server.
Variables ¶
This section is empty.
Functions ¶
func DecodeTransactionError ¶
DecodeTransactionError parses the server's raw err field into either a *TransactionError, an *InstructionError, or nil.
The raw value comes from simulateTransaction or getTransaction's meta.err and is the untyped JSON shape Solana returns:
- nil (success)
- a plain string like "BlockhashNotFound"
- {"InstructionError": [<idx>, "<kind>"]}
- {"InstructionError": [<idx>, {"Custom": <u32>}]}
- {"InstructionError": [<idx>, {"<Kind>": <sub>}]}
Unrecognised shapes are returned as a plain fmt.Errorf rather than silently discarded.
func FirstOrZero ¶
func FirstOrZero[T any](opts []T) *T
FirstOrZero is the exported form of firstOrZero, used by callers that build their own request body (helpers, third-party wrappers).
Types ¶
type AccountInfoCfg ¶
type AccountInfoCfg struct {
Commitment solana.CommitmentLevel `json:"commitment,omitempty"`
Encoding solana.Encoding `json:"encoding,omitempty"`
DataSlice *DataSlice `json:"dataSlice,omitempty"`
MinContextSlot *uint64 `json:"minContextSlot,omitempty"`
}
AccountInfoCfg is the config object for account-data RPC methods that honour {commitment, encoding, dataSlice, minContextSlot}: GetAccountInfo, GetMultipleAccounts, GetProgramAccounts, GetTokenAccountsByOwner, GetTokenAccountsByDelegate.
func (AccountInfoCfg) MarshalJSON ¶
func (c AccountInfoCfg) MarshalJSON() ([]byte, error)
MarshalJSON injects the SDK's default encoding ("base64") into AccountInfoCfg before serialising. Account-data RPCs always need a concrete encoding so the SDK fills in base64 when the caller leaves it blank.
Centralising the default here pays off because five typed methods (GetAccountInfo, GetMultipleAccounts, GetProgramAccounts, GetTokenAccountsByOwner, GetTokenAccountsByDelegate) share this Cfg. Other Cfg types with only one or two callers inject defaults inline in the calling method instead, which avoids the alias-MarshalJSON ceremony for the rare paths.
type BlockCommitment ¶
type BlockCommitment struct {
Commitment []uint64 `json:"commitment"`
TotalStake uint64 `json:"totalStake"`
}
BlockCommitment is the decoded response of GetBlockCommitment.
type BlockProductionRange ¶
type BlockProductionRange struct {
FirstSlot uint64 `json:"firstSlot"`
LastSlot uint64 `json:"lastSlot"`
}
BlockProductionRange describes the slot range covered by a GetBlockProduction response.
type BlockProductionResult ¶
type BlockProductionResult struct {
Slot uint64
Value BlockProductionValue
}
BlockProductionResult is the decoded response of GetBlockProduction.
type BlockProductionValue ¶
type BlockProductionValue struct {
ByIdentity map[string][2]uint64 `json:"byIdentity"`
Range BlockProductionRange `json:"range"`
}
BlockProductionValue is the data portion of a GetBlockProduction response.
type BlockTransaction ¶
type BlockTransaction struct {
Transaction solana.AccountData `json:"transaction"`
Meta *TransactionMeta `json:"meta"`
Version any `json:"version"`
}
BlockTransaction is a single entry in the transactions array of a GetBlock response.
type Client ¶
Client is the typed Solana JSON-RPC client. It embeds *jsonrpc.Client so the underlying transport's Call / batching / retry surface is promoted directly.
func NewClient ¶
NewClient returns a Client connected to the given JSON-RPC endpoint using a Config struct (HTTP transport options).
c := rpc.NewClient("https://api.mainnet-beta.solana.com", jsonrpc.Config{
MaxIdleConnsPerHost: 20,
})
func NewClientFromTransport ¶
NewClientFromTransport wraps an existing *jsonrpc.Client. Use this when you need to share a transport (e.g. one decorated with retry, rate-limit, or metrics middleware) across multiple Client instances.
func NewClientWith ¶
func NewClientWith(endpoint string, opts ...jsonrpc.ClientOption) *Client
NewClientWith returns a Client configured via functional options.
c := rpc.NewClientWith("https://api.mainnet-beta.solana.com",
jsonrpc.WithMaxIdleConnsPerHost(20),
jsonrpc.WithHeader("X-API-Key", "secret"),
)
func (*Client) GetAccountInfo ¶
func (c *Client) GetAccountInfo(ctx context.Context, pubkey solana.PublicKey, cfg ...AccountInfoCfg) (*GetAccountInfoResult, error)
GetAccountInfo fetches the current state of the account at the given address. Encoding defaults to base64 when cfg.Encoding is empty.
func (*Client) GetAddressLookupTable ¶
func (c *Client) GetAddressLookupTable(ctx context.Context, address solana.PublicKey, cfg ...CommitmentWithMinSlotCfg) (*GetAddressLookupTableResult, error)
GetAddressLookupTable fetches and decodes the on-chain state of an Address Lookup Table at the given address. Returns nil, nil if the account does not exist.
Encoding is forced to base64 — the table layout is binary and cannot be requested via jsonParsed. Honoured options: Commitment, MinContextSlot.
func (*Client) GetBalance ¶
func (c *Client) GetBalance(ctx context.Context, pubkey solana.PublicKey, cfg ...CommitmentWithMinSlotCfg) (*GetBalanceResult, error)
GetBalance returns the balance of the account at the given address, in lamports.
func (*Client) GetBlock ¶
func (c *Client) GetBlock(ctx context.Context, slot uint64, cfg ...GetBlockCfg) (*GetBlockResult, error)
GetBlock fetches the content of a single block by slot. Returns nil, nil if the slot is absent or skipped.
SDK-applied defaults when the caller leaves them unset:
- Encoding: base64
- TransactionDetails: "full"
- MaxSupportedTransactionVersion: 0
func (*Client) GetBlockCommitment ¶
GetBlockCommitment returns the commitment for a given block slot.
func (*Client) GetBlockHeight ¶
func (c *Client) GetBlockHeight(ctx context.Context, cfg ...CommitmentWithMinSlotCfg) (uint64, error)
GetBlockHeight returns the current block height.
func (*Client) GetBlockProduction ¶
func (c *Client) GetBlockProduction(ctx context.Context, cfg ...CommitmentCfg) (*BlockProductionResult, error)
GetBlockProduction returns recent block production information.
func (*Client) GetBlockTime ¶
GetBlockTime returns the UNIX timestamp at which the given slot was produced.
func (*Client) GetBlocks ¶
func (c *Client) GetBlocks(ctx context.Context, start uint64, end *uint64, cfg ...CommitmentCfg) ([]uint64, error)
GetBlocks returns the list of confirmed block slots in the inclusive range [start, end]. When end is nil, the cluster's latest confirmed block bounds the range.
func (*Client) GetBlocksWithLimit ¶
func (c *Client) GetBlocksWithLimit(ctx context.Context, startSlot uint64, limit uint64, cfg ...CommitmentCfg) ([]uint64, error)
GetBlocksWithLimit returns a list of confirmed blocks starting at startSlot up to limit blocks.
func (*Client) GetClusterNodes ¶
func (c *Client) GetClusterNodes(ctx context.Context) ([]ClusterNode, error)
GetClusterNodes returns information about all nodes participating in the cluster.
func (*Client) GetEpochInfo ¶
func (c *Client) GetEpochInfo(ctx context.Context, cfg ...CommitmentWithMinSlotCfg) (*EpochInfo, error)
GetEpochInfo returns information about the current epoch.
func (*Client) GetEpochSchedule ¶
func (c *Client) GetEpochSchedule(ctx context.Context) (*EpochSchedule, error)
GetEpochSchedule returns the epoch schedule configuration from the cluster's genesis config.
func (*Client) GetFeeForMessage ¶
func (c *Client) GetFeeForMessage(ctx context.Context, msg *solana.Message, cfg ...CommitmentWithMinSlotCfg) (*GetFeeForMessageResult, error)
GetFeeForMessage computes the fee the cluster would charge for a transaction with the given message.
func (*Client) GetFirstAvailableBlock ¶
GetFirstAvailableBlock returns the slot of the lowest confirmed block not purged from the ledger.
func (*Client) GetGenesisHash ¶
GetGenesisHash returns the genesis hash.
func (*Client) GetHighestSnapshotSlot ¶
func (c *Client) GetHighestSnapshotSlot(ctx context.Context) (*HighestSnapshotSlot, error)
GetHighestSnapshotSlot returns the highest slot for which the node has a snapshot.
func (*Client) GetIdentity ¶
GetIdentity returns the identity public key of the current node.
func (*Client) GetInflationGovernor ¶
func (c *Client) GetInflationGovernor(ctx context.Context, cfg ...CommitmentCfg) (*InflationGovernor, error)
GetInflationGovernor returns the current inflation governor configuration.
func (*Client) GetInflationRate ¶
func (c *Client) GetInflationRate(ctx context.Context) (*InflationRate, error)
GetInflationRate returns the current inflation rate.
func (*Client) GetInflationReward ¶
func (c *Client) GetInflationReward(ctx context.Context, addresses []solana.PublicKey, cfg ...InflationRewardCfg) ([]*InflationReward, error)
GetInflationReward returns the inflation/staking reward for a list of addresses for an epoch. Set cfg.Epoch to query a specific epoch; leave nil for the previous epoch.
func (*Client) GetLargestAccounts ¶
func (c *Client) GetLargestAccounts(ctx context.Context, cfg ...LargestAccountsCfg) ([]LargestAccount, error)
GetLargestAccounts returns the 20 largest accounts by lamport balance. cfg.Filter selects "circulating" or "nonCirculating".
func (*Client) GetLatestBlockhash ¶
func (c *Client) GetLatestBlockhash(ctx context.Context, cfg ...CommitmentWithMinSlotCfg) (*LatestBlockhash, error)
GetLatestBlockhash returns the latest blockhash and its last valid block height.
func (*Client) GetLeaderSchedule ¶
func (c *Client) GetLeaderSchedule(ctx context.Context, slot *uint64, cfg ...LeaderScheduleCfg) (map[string][]uint64, error)
GetLeaderSchedule returns the leader schedule for an epoch. Pass nil for slot to query the current epoch.
func (*Client) GetMaxRetransmitSlot ¶
GetMaxRetransmitSlot returns the max slot seen from the retransmit stage.
func (*Client) GetMaxShredInsertSlot ¶
GetMaxShredInsertSlot returns the max slot seen from after shred insert.
func (*Client) GetMinimumBalanceForRentExemption ¶
func (c *Client) GetMinimumBalanceForRentExemption(ctx context.Context, dataSize uint64, cfg ...CommitmentCfg) (uint64, error)
GetMinimumBalanceForRentExemption returns the minimum lamports needed to make an account rent-exempt.
func (*Client) GetMultipleAccounts ¶
func (c *Client) GetMultipleAccounts(ctx context.Context, addresses []solana.PublicKey, cfg ...AccountInfoCfg) (*GetMultipleAccountsResult, error)
GetMultipleAccounts fetches multiple accounts in a single round trip. Encoding defaults to base64 when cfg.Encoding is empty.
func (*Client) GetProgramAccounts ¶
func (c *Client) GetProgramAccounts(ctx context.Context, program solana.PublicKey, cfg ...AccountInfoCfg) ([]ProgramAccount, error)
GetProgramAccounts returns all accounts owned by the given program. Encoding defaults to base64.
func (*Client) GetRecentPerformanceSamples ¶
func (c *Client) GetRecentPerformanceSamples(ctx context.Context, limit *uint64) ([]PerformanceSample, error)
GetRecentPerformanceSamples returns a list of recent performance samples.
func (*Client) GetRecentPrioritizationFees ¶
func (c *Client) GetRecentPrioritizationFees(ctx context.Context, addresses []solana.PublicKey) ([]PrioritizationFee, error)
GetRecentPrioritizationFees returns the prioritization fees observed in recent slots.
func (*Client) GetSignatureStatuses ¶
func (c *Client) GetSignatureStatuses(ctx context.Context, sigs []solana.Signature, cfg ...SignatureStatusesCfg) (*GetSignatureStatusesResult, error)
GetSignatureStatuses fetches the status of multiple transaction signatures. Set cfg.SearchTransactionHistory to query the long-term transaction archive.
func (*Client) GetSignaturesForAddress ¶
func (c *Client) GetSignaturesForAddress(ctx context.Context, addr solana.PublicKey, cfg ...SignaturesForAddressCfg) ([]*ConfirmedSignatureForAddress, error)
GetSignaturesForAddress fetches the transaction signatures that touched the given address.
func (*Client) GetSlotLeader ¶
func (c *Client) GetSlotLeader(ctx context.Context, cfg ...CommitmentWithMinSlotCfg) (solana.PublicKey, error)
GetSlotLeader returns the public key of the current slot leader.
func (*Client) GetSlotLeaders ¶
func (c *Client) GetSlotLeaders(ctx context.Context, startSlot uint64, limit uint64) ([]solana.PublicKey, error)
GetSlotLeaders returns the slot leaders for a range of slots.
func (*Client) GetStakeActivation ¶
func (c *Client) GetStakeActivation(ctx context.Context, account solana.PublicKey, cfg ...CommitmentWithMinSlotCfg) (*StakeActivation, error)
GetStakeActivation returns the activation state of a stake account.
func (*Client) GetStakeMinimumDelegation ¶
func (c *Client) GetStakeMinimumDelegation(ctx context.Context, cfg ...CommitmentCfg) (uint64, error)
GetStakeMinimumDelegation returns the stake minimum delegation in lamports.
func (*Client) GetSupply ¶
func (c *Client) GetSupply(ctx context.Context, cfg ...CommitmentCfg) (*SupplyResult, error)
GetSupply returns circulating and total SOL supply.
func (*Client) GetTokenAccountBalance ¶
func (c *Client) GetTokenAccountBalance(ctx context.Context, account solana.PublicKey, cfg ...CommitmentCfg) (*GetTokenAccountBalanceResult, error)
GetTokenAccountBalance returns the balance of an SPL Token account.
func (*Client) GetTokenAccountsByDelegate ¶
func (c *Client) GetTokenAccountsByDelegate(ctx context.Context, delegate solana.PublicKey, filter TokenAccountFilter, cfg ...AccountInfoCfg) ([]TokenAccount, error)
GetTokenAccountsByDelegate returns all SPL Token accounts for which the given address has been approved as a delegate. Encoding defaults to base64.
func (*Client) GetTokenAccountsByOwner ¶
func (c *Client) GetTokenAccountsByOwner(ctx context.Context, owner solana.PublicKey, filter TokenAccountFilter, cfg ...AccountInfoCfg) ([]TokenAccount, error)
GetTokenAccountsByOwner returns all SPL Token accounts owned by the given wallet address. Encoding defaults to base64.
func (*Client) GetTokenLargestAccounts ¶
func (c *Client) GetTokenLargestAccounts(ctx context.Context, mint solana.PublicKey, cfg ...CommitmentCfg) ([]TokenLargestAccount, error)
GetTokenLargestAccounts returns the 20 largest accounts for a given SPL Token mint.
func (*Client) GetTokenSupply ¶
func (c *Client) GetTokenSupply(ctx context.Context, mint solana.PublicKey, cfg ...CommitmentCfg) (*GetTokenSupplyResult, error)
GetTokenSupply returns the total supply of an SPL Token mint.
func (*Client) GetTransaction ¶
func (c *Client) GetTransaction(ctx context.Context, sig solana.Signature, cfg ...GetTransactionCfg) (*GetTransactionResult, error)
GetTransaction fetches a single transaction by signature. Returns nil, nil if the signature is not known to the node. Encoding defaults to base64 and MaxSupportedTransactionVersion to 0 when the caller leaves them unset.
func (*Client) GetTransactionCount ¶
func (c *Client) GetTransactionCount(ctx context.Context, cfg ...CommitmentWithMinSlotCfg) (uint64, error)
GetTransactionCount returns the current transaction count from the ledger.
func (*Client) GetVersion ¶
func (c *Client) GetVersion(ctx context.Context) (*SolanaVersion, error)
GetVersion returns the current version of the Solana node.
func (*Client) GetVoteAccounts ¶
func (c *Client) GetVoteAccounts(ctx context.Context, cfg ...CommitmentCfg) (*VoteAccounts, error)
GetVoteAccounts returns the account info and associated stake for all voting accounts.
func (*Client) IsBlockhashValid ¶
func (c *Client) IsBlockhashValid(ctx context.Context, blockhash solana.Hash, cfg ...CommitmentWithMinSlotCfg) (bool, error)
IsBlockhashValid returns whether a blockhash is still valid.
func (*Client) MinimumLedgerSlot ¶
MinimumLedgerSlot returns the lowest slot that the node has information about.
func (*Client) RequestAirdrop ¶
func (c *Client) RequestAirdrop(ctx context.Context, pubkey solana.PublicKey, lamports uint64, cfg ...CommitmentCfg) (solana.Signature, error)
RequestAirdrop asks the cluster to deposit lamports into pubkey. Only valid on devnet and testnet.
func (*Client) SendAndConfirmSignedTransaction ¶
func (c *Client) SendAndConfirmSignedTransaction( ctx context.Context, tx *solana.Transaction, opts ...SendAndConfirmOption, ) (solana.Signature, error)
SendAndConfirmSignedTransaction sends an already-signed transaction and waits for confirmation. Unlike SendAndConfirmTransaction, it performs exactly one send attempt and cannot refresh the blockhash on expiry; use it when the caller has a fully prepared transaction and wants a simple fire-and-wait flow.
func (*Client) SendAndConfirmTransaction ¶
func (c *Client) SendAndConfirmTransaction( ctx context.Context, build TransactionBuilder, opts ...SendAndConfirmOption, ) (solana.Signature, error)
SendAndConfirmTransaction builds, sends, and waits for a Solana transaction to reach the requested commitment level.
The builder is called for each send attempt with the latest blockhash, so callers get automatic blockhash refresh: when a transaction's blockhash expires, SendAndConfirmTransaction fetches a fresh one, rebuilds via the builder, and resubmits — up to WithMaxBlockhashRetries times.
On success it returns the first-signature of the transaction (the payer's). On preflight failure it returns the error from the send call. On execution failure (detected via getSignatureStatuses) it returns the decoded error from DecodeTransactionError, which unwraps to *TransactionError or *InstructionError.
func (*Client) SendRawTransaction ¶
func (c *Client) SendRawTransaction(ctx context.Context, raw []byte, cfg ...SendTxCfg) (solana.Signature, error)
SendRawTransaction broadcasts pre-marshaled transaction bytes to the cluster. Encoding may be base58 or base64; defaults to base64.
func (*Client) SendTransaction ¶
func (c *Client) SendTransaction(ctx context.Context, tx *solana.Transaction, cfg ...SendTxCfg) (solana.Signature, error)
SendTransaction marshals tx and broadcasts it to the cluster. The transaction must already be signed by every required signer.
func (*Client) SimulateTransaction ¶
func (c *Client) SimulateTransaction(ctx context.Context, tx *solana.Transaction, cfg ...SimulateTxCfg) (*SimulateResult, error)
SimulateTransaction simulates the given transaction without broadcasting it. Encoding defaults to base64 when cfg.Encoding is empty.
type ClusterNode ¶
type ClusterNode struct {
Pubkey solana.PublicKey `json:"pubkey"`
Gossip string `json:"gossip"`
TPU string `json:"tpu"`
RPC string `json:"rpc"`
Version string `json:"version"`
FeatureSet *uint32 `json:"featureSet"`
ShredVersion *uint16 `json:"shredVersion"`
}
ClusterNode describes a single node in the cluster.
type CommitmentCfg ¶
type CommitmentCfg struct {
Commitment solana.CommitmentLevel `json:"commitment,omitempty"`
}
CommitmentCfg is the simplest config object accepted by RPC methods that only honour {commitment}: GetSupply, GetVoteAccounts, GetBlockProduction, GetMinimumBalanceForRentExemption, GetStakeMinimumDelegation, GetInflationGovernor, RequestAirdrop, GetTokenLargestAccounts, GetTokenSupply, GetTokenAccountBalance, GetBlocks, GetBlocksWithLimit.
type CommitmentWithEncodingCfg ¶
type CommitmentWithEncodingCfg struct {
Commitment solana.CommitmentLevel `json:"commitment,omitempty"`
Encoding solana.Encoding `json:"encoding,omitempty"`
}
CommitmentWithEncodingCfg is the config object for WebSocket subscriptions that honour {commitment, encoding}: AccountSubscribe, ProgramSubscribe.
type CommitmentWithMinSlotCfg ¶
type CommitmentWithMinSlotCfg struct {
Commitment solana.CommitmentLevel `json:"commitment,omitempty"`
MinContextSlot *uint64 `json:"minContextSlot,omitempty"`
}
CommitmentWithMinSlotCfg is the config object for RPC methods that honour {commitment, minContextSlot}: GetBalance, GetSlot, GetBlockHeight, GetLatestBlockhash, GetEpochInfo, GetSlotLeader, GetTransactionCount, IsBlockhashValid, GetFeeForMessage, GetStakeActivation.
type ConfirmedSignatureForAddress ¶
type ConfirmedSignatureForAddress struct {
Signature string `json:"signature"`
Slot uint64 `json:"slot"`
Err any `json:"err"`
Memo *string `json:"memo"`
BlockTime *int64 `json:"blockTime"`
ConfirmationStatus string `json:"confirmationStatus"`
}
ConfirmedSignatureForAddress is a single entry in the result of GetSignaturesForAddress.
type DataSlice ¶
DataSlice requests a subrange of account data to be returned, reducing bandwidth for large accounts.
type EpochInfo ¶
type EpochInfo struct {
AbsoluteSlot uint64 `json:"absoluteSlot"`
BlockHeight uint64 `json:"blockHeight"`
Epoch uint64 `json:"epoch"`
SlotIndex uint64 `json:"slotIndex"`
SlotsInEpoch uint64 `json:"slotsInEpoch"`
TransactionCount *uint64 `json:"transactionCount"`
}
EpochInfo is the decoded response of GetEpochInfo.
type EpochSchedule ¶
type EpochSchedule struct {
SlotsPerEpoch uint64 `json:"slotsPerEpoch"`
LeaderScheduleSlotOffset uint64 `json:"leaderScheduleSlotOffset"`
Warmup bool `json:"warmup"`
FirstNormalEpoch uint64 `json:"firstNormalEpoch"`
FirstNormalSlot uint64 `json:"firstNormalSlot"`
}
EpochSchedule holds the epoch schedule configuration of the cluster.
type GetAccountInfoResult ¶
type GetAccountInfoResult struct {
Slot uint64
Account *solana.AccountInfo
}
GetAccountInfoResult is the decoded response of GetAccountInfo.
type GetAddressLookupTableResult ¶
type GetAddressLookupTableResult struct {
Slot uint64
State *addresslookuptable.TableState
}
GetAddressLookupTableResult is the decoded response of GetAddressLookupTable.
type GetBalanceResult ¶
GetBalanceResult is the decoded response of GetBalance.
type GetBlockCfg ¶
type GetBlockCfg struct {
Commitment solana.CommitmentLevel `json:"commitment,omitempty"`
Encoding solana.Encoding `json:"encoding,omitempty"`
MaxSupportedTransactionVersion *uint64 `json:"maxSupportedTransactionVersion,omitempty"`
TransactionDetails string `json:"transactionDetails,omitempty"` // "full" | "accounts" | "signatures" | "none"
Rewards *bool `json:"rewards,omitempty"`
}
GetBlockCfg is the config object for GetBlock and BlockSubscribe. TransactionDetails defaults to "full" when empty; Encoding defaults to base64 when empty (both via MarshalJSON below).
type GetBlockResult ¶
type GetBlockResult struct {
Blockhash string `json:"blockhash"`
PreviousBlockhash string `json:"previousBlockhash"`
ParentSlot uint64 `json:"parentSlot"`
Transactions []BlockTransaction `json:"transactions"`
BlockHeight *uint64 `json:"blockHeight"`
BlockTime *int64 `json:"blockTime"`
Rewards []any `json:"rewards"`
}
GetBlockResult is the decoded response of GetBlock.
type GetFeeForMessageResult ¶
GetFeeForMessageResult is the decoded response of GetFeeForMessage.
type GetMultipleAccountsResult ¶
type GetMultipleAccountsResult struct {
Slot uint64
Accounts []*solana.AccountInfo
}
GetMultipleAccountsResult is the decoded response of GetMultipleAccounts.
type GetSignatureStatusesResult ¶
type GetSignatureStatusesResult struct {
Slot uint64
Statuses []*SignatureStatus
}
GetSignatureStatusesResult is the decoded response of GetSignatureStatuses.
type GetTokenAccountBalanceResult ¶
type GetTokenAccountBalanceResult struct {
Slot uint64
Value TokenAmount
}
GetTokenAccountBalanceResult is the decoded response of GetTokenAccountBalance.
type GetTokenSupplyResult ¶
type GetTokenSupplyResult struct {
Slot uint64
Value TokenAmount
}
GetTokenSupplyResult is the decoded response of GetTokenSupply.
type GetTransactionCfg ¶
type GetTransactionCfg struct {
Commitment solana.CommitmentLevel `json:"commitment,omitempty"`
Encoding solana.Encoding `json:"encoding,omitempty"`
MaxSupportedTransactionVersion *uint64 `json:"maxSupportedTransactionVersion,omitempty"`
}
GetTransactionCfg is the config object for GetTransaction.
type GetTransactionResult ¶
type GetTransactionResult struct {
Slot uint64 `json:"slot"`
BlockTime *int64 `json:"blockTime"`
Meta *TransactionMeta `json:"meta"`
Transaction solana.AccountData `json:"transaction"`
Version any `json:"version"`
}
GetTransactionResult is the decoded response of GetTransaction.
type HighestSnapshotSlot ¶
type HighestSnapshotSlot struct {
Full uint64 `json:"full"`
Incremental *uint64 `json:"incremental"`
}
HighestSnapshotSlot is the decoded response of GetHighestSnapshotSlot.
type InflationGovernor ¶
type InflationGovernor struct {
Initial float64 `json:"initial"`
Terminal float64 `json:"terminal"`
Taper float64 `json:"taper"`
Foundation float64 `json:"foundation"`
FoundationTerm float64 `json:"foundationTerm"`
}
InflationGovernor holds the inflation configuration of the cluster.
type InflationRate ¶
type InflationRate struct {
Total float64 `json:"total"`
Validator float64 `json:"validator"`
Foundation float64 `json:"foundation"`
Epoch uint64 `json:"epoch"`
}
InflationRate is the decoded response of GetInflationRate.
type InflationReward ¶
type InflationReward struct {
Epoch uint64 `json:"epoch"`
EffectiveSlot uint64 `json:"effectiveSlot"`
Amount uint64 `json:"amount"`
PostBalance uint64 `json:"postBalance"`
Commission *uint8 `json:"commission"`
}
InflationReward is a single entry in the GetInflationReward response.
type InflationRewardCfg ¶
type InflationRewardCfg struct {
Commitment solana.CommitmentLevel `json:"commitment,omitempty"`
MinContextSlot *uint64 `json:"minContextSlot,omitempty"`
Epoch *uint64 `json:"epoch,omitempty"`
}
InflationRewardCfg is the config object for GetInflationReward.
type InstructionError ¶
InstructionError is a typed transaction error attributed to a single instruction in the transaction. Index is the 0-based position of the failing instruction; Kind is the symbolic name of the failure matching the Solana runtime's InstructionError enum; CustomErrorCode is set when Kind is "Custom" and carries the program-defined u32 error code.
func (*InstructionError) Error ¶
func (e *InstructionError) Error() string
type LargestAccount ¶
type LargestAccount struct {
Address solana.PublicKey `json:"address"`
Lamports uint64 `json:"lamports"`
}
LargestAccount is a single entry in the GetLargestAccounts response.
type LargestAccountsCfg ¶
type LargestAccountsCfg struct {
Commitment solana.CommitmentLevel `json:"commitment,omitempty"`
Filter string `json:"filter,omitempty"`
}
LargestAccountsCfg is the config object for GetLargestAccounts. Filter is "circulating" or "nonCirculating".
type LatestBlockhash ¶
type LatestBlockhash struct {
Slot uint64 `json:"-"`
Blockhash solana.Hash `json:"blockhash"`
LastValidBlockHeight uint64 `json:"lastValidBlockHeight"`
}
LatestBlockhash is the decoded response of GetLatestBlockhash.
type LeaderScheduleCfg ¶
type LeaderScheduleCfg struct {
Commitment solana.CommitmentLevel `json:"commitment,omitempty"`
Identity string `json:"identity,omitempty"`
}
LeaderScheduleCfg is the config object for GetLeaderSchedule.
type LogsSubscribeCfg ¶
type LogsSubscribeCfg struct {
Commitment solana.CommitmentLevel `json:"commitment,omitempty"`
}
LogsSubscribeCfg is the config object for LogsSubscribe.
type PerformanceSample ¶
type PerformanceSample struct {
Slot uint64 `json:"slot"`
NumTransactions uint64 `json:"numTransactions"`
NumSlots uint64 `json:"numSlots"`
SamplePeriodSecs uint16 `json:"samplePeriodSecs"`
NumNonVoteTransactions uint64 `json:"numNonVoteTransactions"`
}
PerformanceSample is a single entry in the GetRecentPerformanceSamples response.
type PrioritizationFee ¶
type PrioritizationFee struct {
Slot uint64 `json:"slot"`
PrioritizationFee uint64 `json:"prioritizationFee"`
}
PrioritizationFee is a single data point in a GetRecentPrioritizationFees response.
type ProgramAccount ¶
type ProgramAccount struct {
Pubkey solana.PublicKey `json:"pubkey"`
Account solana.AccountInfo `json:"account"`
}
ProgramAccount is a single entry in the GetProgramAccounts response.
type SendAndConfirmOption ¶
type SendAndConfirmOption func(*sendConfig)
SendAndConfirmOption configures SendAndConfirmTransaction and SendAndConfirmSignedTransaction.
func WithConfirmTimeout ¶
func WithConfirmTimeout(d time.Duration) SendAndConfirmOption
WithConfirmTimeout caps the total time to wait for confirmation. Default: 60 seconds.
func WithMaxBlockhashRetries ¶
func WithMaxBlockhashRetries(n int) SendAndConfirmOption
WithMaxBlockhashRetries caps the number of blockhash refresh + rebuild + resend cycles SendAndConfirmTransaction will perform before giving up. Default: 3.
func WithPollInterval ¶
func WithPollInterval(d time.Duration) SendAndConfirmOption
WithPollInterval sets the delay between getSignatureStatuses polls while waiting for confirmation. Default: 2 seconds.
func WithSendCommitment ¶
func WithSendCommitment(c solana.CommitmentLevel) SendAndConfirmOption
WithSendCommitment sets the commitment level required to consider a transaction confirmed. Default: Confirmed.
func WithSendSkipPreflight ¶
func WithSendSkipPreflight(b bool) SendAndConfirmOption
WithSendSkipPreflight disables the server's preflight check. Use only when the caller has already simulated the transaction and is sure it is valid.
type SendTxCfg ¶
type SendTxCfg struct {
SkipPreflight *bool `json:"skipPreflight,omitempty"`
PreflightCommitment solana.CommitmentLevel `json:"preflightCommitment,omitempty"`
MaxRetries *uint `json:"maxRetries,omitempty"`
MinContextSlot *uint64 `json:"minContextSlot,omitempty"`
Encoding solana.Encoding `json:"encoding,omitempty"`
}
SendTxCfg is the config object for SendTransaction and SendRawTransaction. Encoding may be base58 or base64; base64 is the default and recommended choice (applied via MarshalJSON below).
type SignatureStatus ¶
type SignatureStatus struct {
Slot uint64 `json:"slot"`
Confirmations *uint64 `json:"confirmations"`
Err any `json:"err"`
ConfirmationStatus string `json:"confirmationStatus"`
}
SignatureStatus is the status of a single transaction signature.
type SignatureStatusesCfg ¶
type SignatureStatusesCfg struct {
SearchTransactionHistory *bool `json:"searchTransactionHistory,omitempty"`
}
SignatureStatusesCfg is the config object for GetSignatureStatuses.
type SignatureSubscribeCfg ¶
type SignatureSubscribeCfg struct {
Commitment solana.CommitmentLevel `json:"commitment,omitempty"`
}
SignatureSubscribeCfg is the config object for SignatureSubscribe.
type SignaturesForAddressCfg ¶
type SignaturesForAddressCfg struct {
Commitment solana.CommitmentLevel `json:"commitment,omitempty"`
MinContextSlot *uint64 `json:"minContextSlot,omitempty"`
Limit *int `json:"limit,omitempty"`
Before string `json:"before,omitempty"`
Until string `json:"until,omitempty"`
}
SignaturesForAddressCfg is the config object for GetSignaturesForAddress.
type SimulateResult ¶
type SimulateResult struct {
Slot uint64 `json:"-"`
Err any `json:"err"`
Logs []string `json:"logs"`
UnitsConsumed *uint64 `json:"unitsConsumed"`
Accounts []*solana.AccountInfo `json:"accounts"`
ReturnData *SimulationReturnData `json:"returnData"`
}
SimulateResult is the decoded response of SimulateTransaction. Slot is filled from the JSON-RPC context envelope after decode; the remaining fields decode directly from the value object via their json: tags. PublicKey decodes from a base58 string via its own UnmarshalJSON.
type SimulateTxCfg ¶
type SimulateTxCfg struct {
Commitment solana.CommitmentLevel `json:"commitment,omitempty"`
SigVerify *bool `json:"sigVerify,omitempty"`
ReplaceRecentBlockhash *bool `json:"replaceRecentBlockhash,omitempty"`
MinContextSlot *uint64 `json:"minContextSlot,omitempty"`
Encoding solana.Encoding `json:"encoding,omitempty"`
}
SimulateTxCfg is the config object for SimulateTransaction.
type SimulationReturnData ¶
type SimulationReturnData struct {
ProgramID solana.PublicKey `json:"programId"`
Data solana.AccountData `json:"data"`
}
SimulationReturnData is the data returned by the last instruction of a simulated transaction.
type SolanaVersion ¶
type SolanaVersion struct {
SolanaCore string `json:"solana-core"`
FeatureSet uint32 `json:"feature-set"`
}
SolanaVersion is the decoded response of GetVersion.
type StakeActivation ¶
type StakeActivation struct {
State string `json:"state"`
Active uint64 `json:"active"`
Inactive uint64 `json:"inactive"`
}
StakeActivation is the decoded response of GetStakeActivation.
type SupplyResult ¶
type SupplyResult struct {
Slot uint64 `json:"-"`
Total uint64 `json:"total"`
Circulating uint64 `json:"circulating"`
NonCirculating uint64 `json:"nonCirculating"`
NonCirculatingAccounts []string `json:"nonCirculatingAccounts"`
}
SupplyResult is the decoded response of GetSupply. Slot is filled from the JSON-RPC context envelope after decode; the rest of the fields decode directly via their json: tags.
type TokenAccount ¶
type TokenAccount struct {
Pubkey solana.PublicKey `json:"pubkey"`
Account solana.AccountInfo `json:"account"`
}
TokenAccount is a single entry in the GetTokenAccountsByOwner and GetTokenAccountsByDelegate responses.
type TokenAccountFilter ¶
TokenAccountFilter selects token accounts by either mint or token program.
type TokenAmount ¶
type TokenAmount struct {
Amount string `json:"amount"`
Decimals uint8 `json:"decimals"`
UIAmount *float64 `json:"uiAmount"`
UIAmountString string `json:"uiAmountString"`
}
TokenAmount is the common shape used by RPC methods that return SPL Token balances.
type TokenLargestAccount ¶
type TokenLargestAccount struct {
Address solana.PublicKey `json:"address"`
Amount string `json:"amount"`
Decimals uint8 `json:"decimals"`
UIAmount *float64 `json:"uiAmount"`
UIAmountString string `json:"uiAmountString"`
}
TokenLargestAccount is a single entry in the GetTokenLargestAccounts response.
type TransactionBuilder ¶
type TransactionBuilder func(ctx context.Context, blockhash solana.Hash) (*solana.Transaction, error)
TransactionBuilder builds a fresh signed transaction with the given blockhash. SendAndConfirmTransaction calls it once per send attempt, so the builder must re-sign with the same signers for every call; captured signers and instructions are the expected pattern.
type TransactionError ¶
type TransactionError struct {
Kind string
}
TransactionError is a top-level transaction error that is not tied to a specific instruction. It carries the symbolic name the Solana runtime reports, for example "BlockhashNotFound", "AccountNotFound", or "AlreadyProcessed".
func (*TransactionError) Error ¶
func (e *TransactionError) Error() string
type TransactionMeta ¶
type TransactionMeta struct {
Err any `json:"err"`
Fee uint64 `json:"fee"`
PreBalances []uint64 `json:"preBalances"`
PostBalances []uint64 `json:"postBalances"`
LogMessages []string `json:"logMessages"`
ComputeUnitsConsumed uint64 `json:"computeUnitsConsumed"`
InnerInstructions []any `json:"innerInstructions,omitempty"`
PreTokenBalances []any `json:"preTokenBalances,omitempty"`
PostTokenBalances []any `json:"postTokenBalances,omitempty"`
Rewards []any `json:"rewards,omitempty"`
LoadedAddresses *struct {
Writable []string `json:"writable"`
Readonly []string `json:"readonly"`
} `json:"loadedAddresses,omitempty"`
}
TransactionMeta summarises execution outcome, balance changes, and logs.
type VoteAccount ¶
type VoteAccount struct {
VotePubkey solana.PublicKey `json:"votePubkey"`
NodePubkey solana.PublicKey `json:"nodePubkey"`
ActivatedStake uint64 `json:"activatedStake"`
EpochVoteAccount bool `json:"epochVoteAccount"`
Commission uint8 `json:"commission"`
LastVote uint64 `json:"lastVote"`
EpochCredits [][3]uint64 `json:"epochCredits"`
RootSlot uint64 `json:"rootSlot"`
}
VoteAccount holds the state of a single vote account.
type VoteAccounts ¶
type VoteAccounts struct {
Current []VoteAccount `json:"current"`
Delinquent []VoteAccount `json:"delinquent"`
}
VoteAccounts is the decoded response of GetVoteAccounts.