Skip to content

Instantly share code, notes, and snippets.

@iGroza
Last active March 12, 2025 05:12
Show Gist options
  • Save iGroza/3ba4b94c1504d91355e1abbae20dd724 to your computer and use it in GitHub Desktop.
Save iGroza/3ba4b94c1504d91355e1abbae20dd724 to your computer and use it in GitHub Desktop.
Solana archive RPC node finder

Solana RPC nodes finder

  • Fetch cluster nodes.
  • Filter them by the .rpc field.
  • Try to connect and call getFirstAvailableBlock().
  • Save to a CSV file: rpc-nodes.csv.

Prerequisites

Ensure you have the following installed:

Running the Script

Execute the script using Deno:

deno run --allow-net --allow-write main.ts
import * as web3 from "npm:@solana/web3.js";
const MAINNET = "https://api.mainnet-beta.solana.com";
const CSV_FILE_NAME = "rpc-nodes.csv";
const connection = new web3.Connection(MAINNET);
const cluster_nodes = await connection.getClusterNodes();
const nodes_with_rpc = cluster_nodes.filter((node) => !!node.rpc);
nodes_with_rpc.push({ rpc: MAINNET } as web3.ContactInfo);
console.log("> Found", nodes_with_rpc.length, "nodes with RPC");
const data: Array<[string, number]> = [];
function withTimeout<T>(promise: Promise<T>, timeout = 30_000): Promise<T> {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
reject(new Error("сonnection timeout exceeded"));
}, timeout);
promise.then(resolve, reject).finally(() => clearTimeout(timer));
});
}
await Promise.all(
nodes_with_rpc.map(async (node, i) => {
try {
console.log(`> Connecting to node ${i + 1}/${nodes_with_rpc.length}`);
const rpc_url = node.rpc?.startsWith("http")
? node.rpc
: `http://${node.rpc}`;
const rpc_connection = new web3.Connection(rpc_url);
const first_available_block = await withTimeout(
rpc_connection.getFirstAvailableBlock()
);
data.push([rpc_url, first_available_block]);
} catch (e) {
console.error("> Error:", node.rpc, '|', (e as Error).message);
}
})
);
console.log("> Active nodes with RPC:", data.length);
const CSV_HEADERS = ["rpc_url", "first_available_block"];
const CSV_DATA = [
CSV_HEADERS.join(","),
...data
.sort((a, b) => Number(a[1]) - Number(b[1]))
.map((row) => row.join(",")),
];
Deno.writeTextFile(CSV_FILE_NAME, CSV_DATA.join("\n"));
console.log(`> Saved to ${CSV_FILE_NAME}`);
rpc_url first_available_block
https://api.mainnet-beta.solana.com 0
http://147.28.175.189:8899 325663490
http://208.91.110.134:8899 325952823
http://213.163.64.146:8900 326077496
http://64.130.32.60:8899 326110098
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment