Solana RPC
getProgramAccountsV2
getProgramAccountsV2는 커서 기반 페이지 매김과 변경된 슬롯 업데이트를 지원하여 대규모 Solana 계정 세트를 쿼리하는 향상된 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": "Invalid params",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32001,
"message": "Unauthorized",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32005,
"message": "Too many requests",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32603,
"message": "Internal error",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32002,
"message": "Service unavailable",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32003,
"message": "Gateway timeout",
"data": {}
},
"id": "1"
}개요
getProgramAccountsV2은 응용 프로그램이 특정 Solana 프로그램이 소유한 대규모 계정을 효율적으로 쿼리해야 할 때를 위해 설계된 표준 getProgramAccounts 메서드의 향상된 버전입니다. 이 메서드는 커서 기반 페이지네이션 및 점진적 업데이트 기능을 도입합니다.
V2의 새로운 기능:
- 커서 기반 페이지네이션: 요청당 1에서 10,000개의 계정까지 제한 설정 가능
- 점진적 업데이트: 최근 수정된 계정만 가져오기 위해
changedSinceSlot사용 - 더 나은 성능: 대량 데이터 세트에서 타임아웃 방지 및 메모리 사용량 감소
- 하위 호환성: 기존의 모든
getProgramAccounts매개변수 지원 - 선택적
withContext:true은slot및apiVersion을result.context아래에 추가합니다; 생략 시false으로 포함되지 않음
주요 혜택
확장 가능한 쿼리
결과를 효율적으로 페이지 화하여 수백만 개의 계정을 가진 프로그램 처리
실시간 동기화
changedSinceSlot을 사용하여 점진적 업데이트 및 실시간 데이터 동기화타임아웃 방지
이전에 타임아웃된 대규모 쿼리가 페이지네이션을 통해 안정적으로 동작
메모리 효율성
데이터를 한 번에 메모리에 적재하는 대신 청크 단위로 처리
페이지네이션 모범 사례
중요한 페이지네이션 동작: 페이지네이션의 끝은 아무 계정도 반환되지 않을 때만 표시됩니다. API는 필터링으로 인해 제한보다 적은 계정을 반환할 수 있으므로
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일 때,
result.context(스냅샷 메타데이터: slot, apiVersion)을 반환하고,
accounts 및 paginationKey을 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"
향상된 페이징 메서드에 대한 매개변수입니다.
계정을 쿼리할 Solana 프로그램 공개 키(주소)이며, base-58로 인코딩된 문자열입니다.
예시:
"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": "Invalid params",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32001,
"message": "Unauthorized",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32005,
"message": "Too many requests",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32603,
"message": "Internal error",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32002,
"message": "Service unavailable",
"data": {}
},
"id": "1"
}{
"jsonrpc": "2.0",
"error": {
"code": -32003,
"message": "Gateway timeout",
"data": {}
},
"id": "1"
}