Solana RPC
getProgramAccountsV2
getProgramAccountsV2は、より大規模なSolanaアカウントセットをクエリするための、カーソルベースのページネーションとchangedSinceSlot更新を備えた拡張getProgramAccountsです。
POST
/
getProgramAccountsV2
curl --request POST \
--url 'https://mainnet.helius-rpc.com/?api-key=' \
--header 'Content-Type: application/json' \
--data '
{
"jsonrpc": "2.0",
"id": "1",
"method": "getProgramAccountsV2",
"params": [
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
{
"encoding": "base64",
"limit": 1000
}
]
}
'import requests
url = "https://mainnet.helius-rpc.com/?api-key="
payload = {
"jsonrpc": "2.0",
"id": "1",
"method": "getProgramAccountsV2",
"params": [
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
{
"encoding": "base64",
"limit": 1000
}
]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
jsonrpc: '2.0',
id: '1',
method: 'getProgramAccountsV2',
params: [
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
{encoding: 'base64', limit: 1000}
]
})
};
fetch('https://mainnet.helius-rpc.com/?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/?api-key=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'jsonrpc' => '2.0',
'id' => '1',
'method' => 'getProgramAccountsV2',
'params' => [
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
[
'encoding' => 'base64',
'limit' => 1000
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://mainnet.helius-rpc.com/?api-key="
payload := strings.NewReader("{\n \"jsonrpc\": \"2.0\",\n \"id\": \"1\",\n \"method\": \"getProgramAccountsV2\",\n \"params\": [\n \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n {\n \"encoding\": \"base64\",\n \"limit\": 1000\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://mainnet.helius-rpc.com/?api-key=")
.header("Content-Type", "application/json")
.body("{\n \"jsonrpc\": \"2.0\",\n \"id\": \"1\",\n \"method\": \"getProgramAccountsV2\",\n \"params\": [\n \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n {\n \"encoding\": \"base64\",\n \"limit\": 1000\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://mainnet.helius-rpc.com/?api-key=")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"jsonrpc\": \"2.0\",\n \"id\": \"1\",\n \"method\": \"getProgramAccountsV2\",\n \"params\": [\n \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n {\n \"encoding\": \"base64\",\n \"limit\": 1000\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "2.0",
"id": "1",
"result": {
"accounts": [
{
"pubkey": "CxELquR1gPP8wHe33gZ4QxqGB3sZ9RSwsJ2KshVewkFY",
"account": {
"lamports": 15298080,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"data": [
"2R9jLfiAQ9bgdcw6h8s44439",
"base64"
],
"executable": false,
"rentEpoch": 28,
"space": 165
}
}
],
"paginationKey": "8WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"
}
}{
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "無効なパラメータ",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32001,
"message": "認証されていません",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32005,
"message": "リクエストが多すぎます",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32603,
"message": "内部エラー",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32002,
"message": "サービス利用不可",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32003,
"message": "ゲートウェイタイムアウト",
"data": {}
},
"id": "1"
}概要
getProgramAccountsV2は、特定のSolanaプログラムが所有する大量のアカウントを効率的にクエリする必要があるアプリケーション向けに設計された標準的なgetProgramAccountsメソッドの強化バージョンです。このメソッドは、カーソルベースのページネーションとインクリメンタルアップデート機能を導入します。
V2の新機能:
- カーソルベースのページネーション: 1から10,000アカウントまでのリクエストごとの制限を設定
- インクリメンタルアップデート:
changedSinceSlotを使用して最近変更されたアカウントのみを取得 - パフォーマンスの向上: 大規模データセットでのタイムアウトを防止し、メモリ使用量を削減
- 後方互換性: すべての既存の
getProgramAccountsパラメータをサポート - オプションの
withContext:trueがslotとapiVersionをresult.contextの下に追加します。省略またはfalseの場合、それらは含まれません
主な利点
スケーラブルなクエリ
結果を効率的にページネーションすることで、数百万のアカウントを持つプログラムを処理
リアルタイム同期
インクリメンタルアップデートとリアルタイムデータ同期のために
changedSinceSlotを使用タイムアウト防止
大きなクエリがページネーションで確実に動作するようになります
メモリ効率
データを一度にすべて読み込むのではなく、チャンクで処理
ページネーションのベストプラクティス
重要なページネーションの動作: ページネーションの終了は、アカウントが返されないときのみ示されます。フィルタリングのため、制限より少ないアカウントが返される場合があります。
paginationKeyがnullになるまでページネーションを続けてください。基本的なページネーションパターン
let allAccounts = [];
let paginationKey = null;
do {
const response = await fetch(`https://mainnet.helius-rpc.com/?api-key=${API_KEY}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: '1',
method: 'getProgramAccountsV2',
params: [
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
{
encoding: 'base64',
filters: [{ dataSize: 165 }],
limit: 5000,
...(paginationKey && { paginationKey })
}
]
})
});
const data = await response.json();
allAccounts.push(...data.result.accounts);
paginationKey = data.result.paginationKey;
} while (paginationKey);
インクリメンタルアップデート
// Get only accounts modified since slot 150000000
const incrementalUpdate = await fetch(`https://mainnet.helius-rpc.com/?api-key=${API_KEY}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: '1',
method: 'getProgramAccountsV2',
params: [
programId,
{
encoding: 'jsonParsed',
limit: 1000,
changedSinceSlot: 150000000
}
]
})
});
パフォーマンスのヒント
最適な制限サイズ: ほとんどのユースケースでは、リクエストごとに1,000〜5,000アカウントの制限が、パフォーマンスと信頼性のベストバランスを提供します。
- 小さい制限から始める (1000) そしてネットワークパフォーマンスに基づいて増やす
- 適切なエンコーディングを使用:
jsonParsedは利便性のため、base64はパフォーマンスのため - フィルタを適用してページネーション前にデータセットサイズを減らす
paginationKeyを保存して中断した場合にクエリを再開する- 応答時間を監視し、制限を適宜調整する
withContext (オプション)
プログラム構成オブジェクト(params[1])でのブール値。resultの形状のみが変化し、フィルタ、制限、ページネーションは変わりません。
// Omitted or false
{ "jsonrpc": "2.0", "id": "1", "result": { "accounts": [], "paginationKey": null } }
// true — snapshot metadata plus page under `result.value`
{ "jsonrpc": "2.0", "id": "1", "result": {
"context": { "slot": 411895550, "apiVersion": "3.1.9" },
"value": { "accounts": [], "paginationKey": null }
}}
getProgramAccountsからの移行
元のメソッドからの移行は簡単です - メソッド名を置き換え、ページネーションパラメータを追加するだけです。{
"jsonrpc": "2.0",
"id": "1",
- "method": "getProgramAccounts",
+ "method": "getProgramAccountsV2",
"params": [
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
{
"encoding": "base64",
"filters": [{ "dataSize": 165 }],
+ "limit": 5000
}
]
}
関連メソッド
getProgramAccounts
ページネーションなしの元のメソッド
getTokenAccountsByOwnerV2
トークンアカウントクエリ用のV2メソッド
リクエストパラメータ
string
必須
Solanaプログラムの公開鍵(アドレス)、base-58エンコードされた文字列としてクエリするアカウントです。
string
リクエストのコミットメントレベル。
confirmedfinalizedprocessed
number
リクエストが評価されることのできる最小スロット。
boolean
trueの場合、インスタンスメタデータ(slot、apiVersion)を返し、accountsをresult.valueの下にネストします。省略またはfalseの場合、これらのフィールドはresultの上に直接表示されます(例: result.accounts)。同じフィルタと制限が適用されます。string
返されるアカウントデータのエンコーディングフォーマット。
jsonParsedbase58base64base64+zstd
object
アカウントのデータのスライスをリクエストします。
number
返すバイト数。
number
読み始めるバイトオフセット。
number
リクエストごとに返す最大アカウント数(1〜10,000)。
string
次のページを取得するためのbase-58エンコードされたページネーションクルーザー。前の応答からpaginationKeyを使用します。
number
このスロット番号以降に変更されたアカウントのみを返します。インクリメンタルアップデートに便利です。
array
特定のSolanaアカウントデータパターンを効率的にクエリするための強力なフィルタリングシステム。
ボディ
application/json
JSON-RPC プロトコルバージョン。
利用可能なオプション:
2.0 例:
"2.0"
リクエストの一意の識別子。
例:
"1"
呼び出すRPCメソッドの名前。
利用可能なオプション:
getProgramAccountsV2 例:
"getProgramAccountsV2"
強化されたページネーションメソッドのパラメータ。
ベース58エンコードされた文字列としてのSolanaプログラム公開鍵(アドレス)で、アカウントを照会します。
例:
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
レスポンス
ページネートされたプログラムアカウントを正常に取得しました。
このページは役に立ちましたか?
⌘I
getProgramAccountsV2
curl --request POST \
--url 'https://mainnet.helius-rpc.com/?api-key=' \
--header 'Content-Type: application/json' \
--data '
{
"jsonrpc": "2.0",
"id": "1",
"method": "getProgramAccountsV2",
"params": [
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
{
"encoding": "base64",
"limit": 1000
}
]
}
'import requests
url = "https://mainnet.helius-rpc.com/?api-key="
payload = {
"jsonrpc": "2.0",
"id": "1",
"method": "getProgramAccountsV2",
"params": [
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
{
"encoding": "base64",
"limit": 1000
}
]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
jsonrpc: '2.0',
id: '1',
method: 'getProgramAccountsV2',
params: [
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
{encoding: 'base64', limit: 1000}
]
})
};
fetch('https://mainnet.helius-rpc.com/?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/?api-key=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'jsonrpc' => '2.0',
'id' => '1',
'method' => 'getProgramAccountsV2',
'params' => [
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
[
'encoding' => 'base64',
'limit' => 1000
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://mainnet.helius-rpc.com/?api-key="
payload := strings.NewReader("{\n \"jsonrpc\": \"2.0\",\n \"id\": \"1\",\n \"method\": \"getProgramAccountsV2\",\n \"params\": [\n \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n {\n \"encoding\": \"base64\",\n \"limit\": 1000\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://mainnet.helius-rpc.com/?api-key=")
.header("Content-Type", "application/json")
.body("{\n \"jsonrpc\": \"2.0\",\n \"id\": \"1\",\n \"method\": \"getProgramAccountsV2\",\n \"params\": [\n \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n {\n \"encoding\": \"base64\",\n \"limit\": 1000\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://mainnet.helius-rpc.com/?api-key=")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"jsonrpc\": \"2.0\",\n \"id\": \"1\",\n \"method\": \"getProgramAccountsV2\",\n \"params\": [\n \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n {\n \"encoding\": \"base64\",\n \"limit\": 1000\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "2.0",
"id": "1",
"result": {
"accounts": [
{
"pubkey": "CxELquR1gPP8wHe33gZ4QxqGB3sZ9RSwsJ2KshVewkFY",
"account": {
"lamports": 15298080,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"data": [
"2R9jLfiAQ9bgdcw6h8s44439",
"base64"
],
"executable": false,
"rentEpoch": 28,
"space": 165
}
}
],
"paginationKey": "8WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"
}
}{
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "無効なパラメータ",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32001,
"message": "認証されていません",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32005,
"message": "リクエストが多すぎます",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32603,
"message": "内部エラー",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32002,
"message": "サービス利用不可",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32003,
"message": "ゲートウェイタイムアウト",
"data": {}
},
"id": "1"
}