How to inspect a Solana program
Fetch program metadata, check if it's upgradeable, and retrieve the Anchor IDL. Copy the code below to add program inspection to your app.
Interactive Demo
Copy the code
These snippets show exactly how to inspect programs. Paste them into your project.
1. Fetch program metadata
Use getAccountInfo with jsonParsed encoding to get program details.
// Get program account info (metadata, owner, executable status)
import { createSolanaRpc } from '@solana/kit';
const rpc = createSolanaRpc('https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY');
// Fetch program account info
const programId = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
const accountInfo = await rpc.getAccountInfo(programId, {
encoding: 'jsonParsed'
}).send();
console.log('Executable:', accountInfo.value?.executable);
console.log('Owner:', accountInfo.value?.owner);
console.log('Lamports:', accountInfo.value?.lamports);
console.log('Space:', accountInfo.value?.space);2. Check upgrade authority
Determine if a program is upgradeable and who controls it by fetching the ProgramData account.
// Get upgrade authority for upgradeable programs
import { createSolanaRpc } from '@solana/kit';
const rpc = createSolanaRpc('https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY');
// Step 1: Get program account to find ProgramData address
const programId = 'JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4';
const programInfo = await rpc.getAccountInfo(programId, {
encoding: 'jsonParsed'
}).send();
const programDataAddress = programInfo.value?.data?.parsed?.info?.programData;
// Step 2: Get ProgramData account for upgrade authority
const programDataInfo = await rpc.getAccountInfo(programDataAddress, {
encoding: 'jsonParsed'
}).send();
const upgradeAuthority = programDataInfo.value?.data?.parsed?.info?.authority;
const lastDeploySlot = programDataInfo.value?.data?.parsed?.info?.slot;
console.log('Upgrade Authority:', upgradeAuthority || 'Immutable (frozen)');
console.log('Last Deploy Slot:', lastDeploySlot);3. Retrieve Anchor IDL
Fetch the on-chain IDL for Anchor programs using @coral-xyz/anchor.
// Fetch on-chain Anchor IDL
import { Program } from '@coral-xyz/anchor';
import { Connection, PublicKey } from '@solana/web3.js';
const connection = new Connection(
'https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY'
);
// Fetch on-chain IDL (requires program to have published IDL)
const programId = new PublicKey('whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc');
const idl = await Program.fetchIdl(programId, { connection });
if (idl) {
console.log('Program Name:', idl.name);
console.log('Instructions:', idl.instructions.map(i => i.name));
console.log('Accounts:', idl.accounts?.map(a => a.name));
} else {
console.log('No IDL found on-chain');
}RPC Methods Used
getAccountInfo- Fetch any account's data with jsonParsed encoding
Notes
- - Not all programs have on-chain IDLs. Only Anchor programs with published IDLs can be fetched.
- - Programs owned by BPFLoaderUpgradeab1e are upgradeable; their upgrade authority is stored in a separate ProgramData account.
- - Native programs (System, Token, etc.) don't have upgrade authority - they're built into the validator.