解析事件
列出 IDL 版本
列出 Parsed Events 为某个 Solana 程序提供的所有 IDL 版本,以及每个版本开始生效的槽位。
GET
/
v1
/
parsed-events
/
idl
/
{programId}
列出 IDL 版本
curl --request GET \
--url 'https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}?api-key='import requests
url = "https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}?api-key="
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}?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}?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}?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}?api-key=")
.asString();require 'uri'
require 'net/http'
url = URI("https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}?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[
{
"slot": 182747476,
"sources": [
"anchor"
]
},
{
"slot": 205509752,
"sources": [
"anchor"
]
},
{
"slot": 206074074,
"sources": [
"anchor"
]
}
]{
"error": "invalid program id: notanaddress: String is the wrong size"
}Unauthorized{
"error": "no IDLs found for program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
}此页面上的路径参数、响应模式和示例均根据 OpenAPI 定义生成。
列出 IDL 版本会从 Parsed Events 和 Parsed Streams 用于解码指令的 IDL 目录中,返回程序接口的历史记录。每一项代表一个版本,并通过其开始生效的槽位进行标识。各项按从旧到新的顺序排列,因此最后一项是当前版本。
将响应中的任意
要检测随时间发生的变更,请存储你上次看到的版本所对应的
其他错误会返回包含
slot 传递给获取 IDL,即可获取该版本的 IDL 文档。Orb 浏览器使用这些端点显示程序 IDL。
使用场景
- 跟踪接口变更。 定期轮询你所依赖程序的“列出 IDL 版本”。出现新版本时,使用“获取 IDL”获取新版本和上一版本,并比较它们的
instructions。新增管理员或权限指令时,值得进行安全审查。 - 检查目录覆盖范围。
404表示目录中没有该程序的 IDL。SPL Token 等程序改由内置解码器解码,因此也会返回404。
示例:检测新的 IDL 版本
此脚本会列出程序的 IDL 版本,获取最新的两个版本,并打印新增或移除的指令:diff-idl-versions.js
const API_KEY = process.env.HELIUS_API_KEY;
if (!API_KEY) {
console.error("Missing HELIUS_API_KEY.");
process.exit(1);
}
const BASE = "https://mainnet.helius-rpc.com/v1/parsed-events/idl";
const PROGRAM_ID = "KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD";
async function get(path) {
const response = await fetch(`${BASE}/${path}?api-key=${API_KEY}`);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
return response.json();
}
const versions = await get(PROGRAM_ID);
if (versions.length < 2) {
console.log("Fewer than two IDL versions; nothing to compare.");
process.exit(0);
}
const [previous, latest] = versions.slice(-2);
const [before, after] = await Promise.all([
get(`${PROGRAM_ID}/${previous.slot}`),
get(`${PROGRAM_ID}/${latest.slot}`),
]);
const names = (idl) => new Set(idl.instructions.map((ix) => ix.name));
const beforeNames = names(before);
const afterNames = names(after);
console.log(`Comparing slot ${previous.slot} with slot ${latest.slot}`);
console.log("Added:", [...afterNames].filter((name) => !beforeNames.has(name)));
console.log("Removed:", [...beforeNames].filter((name) => !afterNames.has(name)));
slot,并在每次轮询时与其进行比较。
积分
每个请求消耗 10 积分,所有套餐均可使用。上面的示例会发出三个请求,因此消耗 30 积分。请参阅积分。错误
| 状态 | 发生条件 |
|---|---|
400 | programId 不是有效的 base58 地址。 |
401 | API 密钥缺失或无效。响应正文为纯文本:Unauthorized。 |
404 | 目录中没有该程序的 IDL。 |
error 消息的 JSON 正文,例如 {"error": "no IDLs found for program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"}。
请求参数
string
必填
程序地址,使用 base58 编码。
此页面对您有帮助吗?
⌘I
列出 IDL 版本
curl --request GET \
--url 'https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}?api-key='import requests
url = "https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}?api-key="
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}?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}?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}?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}?api-key=")
.asString();require 'uri'
require 'net/http'
url = URI("https://mainnet.helius-rpc.com/v1/parsed-events/idl/{programId}?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[
{
"slot": 182747476,
"sources": [
"anchor"
]
},
{
"slot": 205509752,
"sources": [
"anchor"
]
},
{
"slot": 206074074,
"sources": [
"anchor"
]
}
]{
"error": "invalid program id: notanaddress: String is the wrong size"
}Unauthorized{
"error": "no IDLs found for program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
}