Is there any way to get all anchor idl's? Right now the CLI supports the command anchor idl fetch <account>, but I'd like something like anchor idl fetch --all, or a way to fetch all anchor program accounts.

1 Answer 1


Such call is a bit of an edge case and very heavy.

If you really need to find all IDLs you can craft this manually but make sure you are using your own RPC provider, this would probably not work and is not recommended to do on a public endpoint.

import { idlAddress } from '@project-serum/anchor';
import { Connection } from '@solana/project-serum';

const connection = new Connection(RPC_URL);

// Start with finding all programs
// there is probably better filter to ignore closed accounts
const programAccounts = await connection.getProgramAccounts(
  new PublicKey("BPFLoaderUpgradeab1e11111111111111111111111"),
    dataSlice: { offset: 0, length: 1 },

// Then check if that program has something looking like an IDL
// You probably need to batch this part using connection.getMultipleAccountInfos
for (const {pubkey, account} of programAccounts) {
    const address = idlAddress(pubkey);
    const idlAccountInfo = await connection.getAccountInfo(address):
    if (idlAccountInfo) {
        // Decode idlAccountInfo.data and check if valid json...
        // do what you want like save as <program-id>-idl.json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.