library / Blockchain ideas / BI0081
Deprecated RPC method audit
A team with an older app gets a list of the removed RPC methods it still calls. One batch probes the old names against the endpoint, a scan finds them in source files, and each hit maps to its current replacement.
Why the call fails
A mini app written against an older @solana/web3.js still calls Connection.getRecentBlockhash. The library sends the method name getRecentBlockhash to the node, and the validator software dropped that name in its 2.0 release, together with other older methods, most of which getBlock, getSignaturesForAddress and the fee calls replaced.
A node on current Solana answers -32601, method not found, and the library wraps the reply as failed to get recent blockhash: Method not found.
On Carbium, `-32601` covers a method the endpoint does not serve and a name nobody knows. Both get the same treatment: check the method and do not retry, since the next call returns the same code.
One error names one call. A team that finds it usually has more, spread over files nobody has opened in a year, and each one shows up only when a user reaches that screen. The audit lists the ones in its table before a user does.
Old names and their replacements
These ten names are deprecated reads that the 2.0 release removed and that have a direct replacement. All of them are reads, so a probe with empty params changes nothing.
| Removed method | Replacement | What changes in the reply |
|---|---|---|
| getRecentBlockhash | getLatestBlockhash | feeCalculator is gone and lastValidBlockHeight is new |
| getFees | getLatestBlockhash, getFeeForMessage | the fee comes from the message you plan to send |
| getFeeCalculatorForBlockhash | isBlockhashValid, getFeeForMessage | validity is a boolean and the fee is a separate call |
| getFeeRateGovernor | getFeeForMessage | ask for the fee of the message itself |
| getSnapshotSlot | getHighestSnapshotSlot | the reply carries full and incremental slots |
| getConfirmedBlock | getBlock | send maxSupportedTransactionVersion: 1 with an encoding |
| getConfirmedBlocks | getBlocks | same slot list |
| getConfirmedBlocksWithLimit | getBlocksWithLimit | same slot list |
| getConfirmedSignaturesForAddress2 | getSignaturesForAddress | same rows, and history reaches back 30 days at most here |
| getConfirmedTransaction | getTransaction | send maxSupportedTransactionVersion: 1; an older signature can answer null |
Probe the replacement as well before you rewrite a call. A replacement the endpoint does not serve answers -32601 too.
Probing in one batch
A JSON-RPC batch is an array of request objects in one POST. The RPC endpoint takes up to 100 calls in one batch with no added envelope, so ten old names need one request and a list of your own can grow tenfold.
The audit sends one request per old name with empty params and reads the code in each answer.
- -32601 means the name is gone. Rewrite the call.
- -32602 means the name reached a method: it exists, and the empty params were the problem. Any other code needs reading before you call the name live.
- A result means the name answers and needs no change.
Match each answer to its request by id. A batch reply does not promise the order of the requests.
Scanning source files
The probe shows which names the endpoint rejects. The scan shows where your code sends them. Pass one or more files and the script reads each one line by line, matches every old name as a whole word, and prints file:line name -> replacement.
Whole-word matching keeps getConfirmedBlock from firing on getConfirmedBlocks, which has a different replacement. To cover a project, hand it the output of git ls-files '*.js'.
A path that cannot be read prints a message and the run goes on, so one missing file never hides the rest.
The build
The code needs @solana/kit and what Node 24 ships. Node strips the types on load, so node main.ts runs the file as written.
- Read CARBIUM_KEY and exit with a message when it is unset.
- Scan each path argument for the ten names.
- Send one batch of the ten names to CARBIUM_RPC_URL, with the key in the x-api-key header, and print each name, its answer code and the replacement.
- Call getLatestBlockhash through @solana/kit and print the blockhash with its lastValidBlockHeight, the last block height at which a transaction signed with it can still land.
// BI0081 · Deprecated RPC method audit// https://carbium.sh/library/blockchainideas/deprecated-rpc-method-audit// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { createDefaultRpcTransport, createSolanaRpcFromTransport } from '@solana/kit';import { readFileSync } from 'node:fs';const key = process.env.CARBIUM_KEY;if (!key) { console.error('Set CARBIUM_KEY to your Carbium API key.'); process.exit(1);}const headers = { 'x-api-key': key };const url = process.env.CARBIUM_RPC_URL ?? 'https://services.carbium.sh';// Methods the validator software removed, with what replaced each.const replacements: Record<string, string> = { getRecentBlockhash: 'getLatestBlockhash', getFees: 'getLatestBlockhash + getFeeForMessage', getFeeCalculatorForBlockhash: 'isBlockhashValid + getFeeForMessage', getFeeRateGovernor: 'getFeeForMessage', getSnapshotSlot: 'getHighestSnapshotSlot', getConfirmedBlock: 'getBlock', getConfirmedBlocks: 'getBlocks', getConfirmedBlocksWithLimit: 'getBlocksWithLimit', getConfirmedSignaturesForAddress2: 'getSignaturesForAddress', getConfirmedTransaction: 'getTransaction',};const names = Object.keys(replacements);const word = /[A-Za-z0-9_]/;const why = (e: unknown): string => (e instanceof Error ? e.message : String(e));function hasName(line: string, name: string): boolean { for (let at = line.indexOf(name); at >= 0; at = line.indexOf(name, at + 1)) { const before = line[at - 1]; const after = line[at + name.length]; if (!(before && word.test(before)) && !(after && word.test(after))) return true; } return false;}function scan(path: string): void { let hits = 0; readFileSync(path, 'utf8').split('\n').forEach((text, i) => { for (const name of names) { if (hasName(text, name)) { hits++; console.log(`${path}:${i + 1} ${name} -> ${replacements[name]}`); } } }); console.log(`${path}: ${hits} hit(s)`);}async function probe(): Promise<string[]> { const batch = names.map((method, id) => ({ jsonrpc: '2.0', id, method, params: [] })); const res = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/json', ...headers }, body: JSON.stringify(batch), }); if (!res.ok) throw new Error(`HTTP ${res.status}`); const answers = (await res.json()) as { id: number; error?: { code: number } }[]; if (!Array.isArray(answers)) throw new Error('reply is not a batch array'); return answers.sort((a, b) => a.id - b.id).map((a) => { const code = a.error ? a.error.code : 'result'; const verdict = code === -32601 ? `gone, use ${replacements[names[a.id]]}` : 'answers'; return `${names[a.id].padEnd(34)} ${String(code).padEnd(7)} ${verdict}`; });}async function main(): Promise<void> { for (const path of process.argv.slice(2)) { try { scan(path); } catch (e) { console.error(`cannot read ${path}: ${why(e)}`); } } const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers })); // The blockhash call asks for confirmed. const [probed, fresh] = await Promise.allSettled([ probe(), rpc.getLatestBlockhash({ commitment: 'confirmed' }).send(), ]); if (probed.status === 'fulfilled') probed.value.forEach((line) => console.log(line)); else console.error(`probe failed: ${why(probed.reason)}`); if (fresh.status === 'fulfilled') { const { blockhash, lastValidBlockHeight } = fresh.value.value; console.log(`blockhash ${blockhash}, last valid block height ${lastValidBlockHeight}`); } else console.error(`getLatestBlockhash failed: ${why(fresh.reason)}`);}main();
run: CARBIUM_KEY=<YOUR_KEY> node main.ts src/app.js src/wallet.js
The blockhash call asks for confirmed. The probe and the blockhash call settle on their own, so a failure in one prints its reason and the other still runs. With no path argument the run covers the endpoint alone. The blockhash line doubles as the check that the replacement works before you wire it into the app. For signing on a machine with no network, see the Blockhash relay for offline signers, and for a first call from scratch see First Solana RPC API call.
Where it ends
- The scan reads your source files only. A dependency that pins an old library version sends removed names from inside node_modules or a built bundle, and a name assembled from string pieces at run time never appears as one word. The probe shows the endpoint's side, and the scan takes files, so pass those files by path, as in node main.ts $(find node_modules/@solana dist -name '*.js').
- In a minified bundle every hit lands on line 1, so search inside the file for the name.
- A probe with empty params proves a name exists and says nothing about whether a call with real params works. Only the replacement call itself proves that.
- Response shapes differ, so the rename is half the migration. Fields such as feeCalculator have no counterpart, and the maxSupportedTransactionVersion setting decides whether getBlock and getTransaction answer -32015 for a v1 transaction.
- Some -32601 answers have no replacement. getTokenLargestAccounts, getProgramAccountsV2 and six more methods are not served on this endpoint, and no rename brings them back.
- The table holds ten names. The same release also removed getStakeActivation, which has no single replacement: read the stake account with getAccountInfo and work out activation against the stake history sysvar. Add it, and any name from a custom wrapper, as an entry in replacements.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The batch fails with HTTP 401 and no answer array. | The key is unknown to the endpoint. Attach the whole key in CARBIUM_KEY, with no trailing space or line break. |
| A name answers -32602 and you list it as removed. | -32602 means the name reached a method and the empty params failed validation. Only -32601 means the name is missing. |
| The scan finds nothing, yet the error persists in the browser. | The call sits in a dependency or a built bundle. The script cannot take a folder, so pass the bundle file and the dependency's .js files by path, for example through find node_modules dist -name '*.js', and search inside a minified file for the name. |
| A rewritten call answers -32601 again. | The replacement is not served here either. Probe it, check its spelling, and do not retry it. |
| The script prints probe failed but still prints a blockhash, or the reverse. | The two parts run on their own. Read the printed reason for the failed one, fix it, and run again. |
| The app throws on a missing field after the rename. | The reply shape changed. Read value.blockhash and value.lastValidBlockHeight from getLatestBlockhash and drop reads of feeCalculator. |
Questions
Why does retrying never help on -32601?
The name is absent from the endpoint, so every call returns the same code. Check the method name and move to the replacement.
Can I pin an older web3.js to keep the old call?
The older library still sends the old name, and the node still answers -32601. Pinning changes which client code runs and brings no method back.
How many names can one batch carry?
Up to 100 calls. The table has ten, so there is room to add the names from your own wrappers.
Why does getFees now take two calls?
getFees returned a blockhash and a fee together. The replacements split the job: getLatestBlockhash returns the blockhash and lastValidBlockHeight, and getFeeForMessage prices the message you plan to send.