Solana RPC Methods & Documentation

通过 HTTP 和 Websocket 方法,使用 JSON RPC API 直接与 Solana 节点交互。

配置状态承诺 #

对于预检和交易处理,Solana 节点根据客户端设置的承诺要求选择要查询的银行状态。 该 承诺描述了区块在该时间点的最终确定情况。 查询账本状态时,建议使用较低级别的承诺 来 报告进度,使用较高级别的承诺来确保状态不会回滚。

按照承诺的降序(最最终确定到最不最终确定),客户可以指定:

  • finalized(已完成) - 节点将查询由集群绝大多数人确认已达到最大锁定的最新块,这 意味着集群已识别该块已完成。
  • confirmed(已确认) - 节点将查询集群中绝大多数投票的最新区块。
    • 它包含了来自gossip和重播的投票。
    • 它不计算对某个区块的后代的投票,只计算对该区块的直接投票。
    • 此确认级别还支持 1.3 版及更高版本中的“乐观确认”保证。
  • processed(处理过) - 节点将查询其最近的块。 请注意,该块仍然可能被集群跳过。

对于串行处理许多相关交易,建议使用confirmed(已确认)的提交,它可以平衡速度与回 滚安全性。 为了完全安全,建议使用finalized(已完成)承诺。

默认的承诺 #

If commitment configuration is not provided, the node will default to finalized commitment

只有查询银行状态的方法才接受承诺参数。 它们在下面的API参考中有说明。

RpcResponse Structure #

Many methods that take a commitment parameter return an RpcResponse JSON object comprised of two parts:

  • context : An RpcResponseContext JSON structure including a slot field at which the operation was evaluated.
  • value : The value returned by the operation itself.

Parsed Responses #

Some methods support an encoding parameter, and can return account or instruction data in parsed JSON format if "encoding":"jsonParsed" is requested and the node has a parser for the owning program. Solana nodes currently support JSON parsing for the following native and SPL programs:

ProgramAccount StateInstructions
Address Lookupv1.15.0v1.15.0
BPF Loadern/astable
BPF Upgradeable Loaderstablestable
Configstable
SPL Associated Token Accountn/astable
SPL Memon/astable
SPL Tokenstablestable
SPL Token 2022stablestable
Stakestablestable
Votestablestable

The list of account parsers can be found here, and instruction parsers here.

Filter criteria #

Some methods support providing a filters object to enable pre-filtering the data returned within the RpcResponse JSON object. The following filters exist:

  • memcmp: object - compares a provided series of bytes with program account data at a particular offset. Fields:

    • offset: usize - offset into program account data to start comparison
    • bytes: string - data to match, as encoded string
    • encoding: string - encoding for filter bytes data, either "base58" or "base64". Data is limited in size to 128 or fewer decoded bytes.
      NEW: This field, and base64 support generally, is only available in solana-core v1.14.0 or newer. Please omit when querying nodes on earlier versions
  • dataSize: u64 - compares the program account data length with the provided data size