解析事件
获取 IDL
从解析事件用于解码指令的目录中,获取 Solana 程序在任意时隙生效的 IDL。
GET
/
v1
/
parsed-events
/
idl
/
{programId}
/
{slot}
获取 IDL
curl --request GET \
--url 'https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}/{slot}?api-key='import requests
url = "https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}/{slot}?api-key="
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}/{slot}?api-key=', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}/{slot}?api-key=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}/{slot}?api-key="
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}/{slot}?api-key=")
.asString();require 'uri'
require 'net/http'
url = URI("https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}/{slot}?api-key=")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"name": "kamino_lending",
"version": "0.1.0",
"instructions": [
{
"name": "refreshObligation",
"accounts": [
{
"name": "lendingMarket",
"isMut": false,
"isSigner": false
},
{
"name": "obligation",
"isMut": true,
"isSigner": false
}
],
"args": []
}
],
"errors": [
{
"code": 6000,
"name": "InvalidMarketAuthority",
"msg": "Market authority is invalid"
}
]
}本页中的路径参数、响应模式和示例均根据 OpenAPI 定义生成。
“获取 IDL”会返回程序在某个时隙的 IDL:即在
两种格式都包含
其他错误会返回包含
slot 或之前生效的最新版本。slot 无需与某个版本完全匹配,因此你可以传入历史上的任意时间点。要获取特定版本,请传入其在列出 IDL 版本中的 slot。
该 IDL 来自解析事件和解析流用于解码指令的同一目录。Orb 浏览器使用这些端点显示程序 IDL。
使用场景
- 使用正确的接口解码历史记录。 传入交易的时隙,即可获取交易执行时生效的 IDL。程序的指令和账户会随时间变化,因此当前 IDL 可能会错误解析较早的交易。
- 查找用于筛选器的准确名称。 扫描交易历史记录
match.programs[].instructions接受 IDL 中定义的指令名称。 - 审查接口变更。 获取两个版本并比较其
instructions,了解升级添加或移除了哪些内容。请参阅列出 IDL 版本中的示例。
IDL 格式
响应是按存储形式返回的 IDL 文档。目录中的程序使用两种 Anchor 格式之一,同一程序的不同版本可能同时使用这两种格式。读取前,请先确认收到的格式:| 旧版 Anchor(0.30 之前) | Anchor 0.30+ | |
|---|---|---|
| 程序名称和版本 | 顶层 name 和 version | metadata.name 和 metadata.version |
| 程序地址 | 无顶层 address | 顶层 address |
| 指令判别器 | 不包含 | instructions[].discriminator |
| 指令账户标志 | isMut、isSigner | writable、signer |
instructions。大多数 IDL 还包含 accounts、types 和 errors,许多 IDL 还包含 events。
积分
每个请求消耗 10 积分,所有套餐均可使用。请参阅积分。错误
| 状态 | 发生条件 |
|---|---|
400 | programId 不是有效的 base58 地址,或 slot 不是无符号 64 位整数。 |
401 | API 密钥缺失或无效。响应正文为纯文本:Unauthorized。 |
404 | 目录中没有该程序的 IDL,或在 slot 或之前没有生效的版本。 |
error 消息的 JSON 正文,例如 {"error": "no IDL found for program KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD at or before slot 1"}。
请求参数
string
必填
程序地址,使用 base58 编码。
number
必填
要查询的时隙。它无需与某个版本的激活时隙匹配。传入“列出 IDL 版本”中的
slot 可获取该确切版本;传入交易的时隙可获取该交易执行时生效的 IDL。授权
路径参数
程序地址,使用 base58 编码。
示例:
"KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD"
要查询的时隙。它不需要与某个版本的激活时隙一致。传入“列出 IDL 版本”返回的 slot 可获取该确切版本,传入交易的时隙则可获取交易执行时生效的 IDL。
必填范围:
x >= 0示例:
205509752
响应
按存储时的原样返回 IDL 文档。可能返回旧版 Anchor 格式或 Anchor 0.30+ 格式,因此请在读取前检查收到的是哪种格式。
按存储时的原样返回 IDL 文档。可能出现两种格式:
- 旧版 Anchor(0.30 之前):顶层包含
name和version。指令账户使用isMut和isSigner。 - Anchor 0.30+:顶层包含
address和metadata(name、version、spec、description)。指令包含discriminator,指令账户使用writable和signer。
两种格式都包含 instructions。大多数 IDL 还包含 accounts、types 和 errors,许多 IDL 还包含 events。同一程序的不同版本可以使用不同格式。
此页面对您有帮助吗?
⌘I
获取 IDL
curl --request GET \
--url 'https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}/{slot}?api-key='import requests
url = "https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}/{slot}?api-key="
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}/{slot}?api-key=', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}/{slot}?api-key=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}/{slot}?api-key="
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}/{slot}?api-key=")
.asString();require 'uri'
require 'net/http'
url = URI("https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}/{slot}?api-key=")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"name": "kamino_lending",
"version": "0.1.0",
"instructions": [
{
"name": "refreshObligation",
"accounts": [
{
"name": "lendingMarket",
"isMut": false,
"isSigner": false
},
{
"name": "obligation",
"isMut": true,
"isSigner": false
}
],
"args": []
}
],
"errors": [
{
"code": 6000,
"name": "InvalidMarketAuthority",
"msg": "Market authority is invalid"
}
]
}