Skip to main content
1 of 2
Arowana
  • 2.4k
  • 3
  • 9

Such call is a bit edge cases 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
    }
}
Arowana
  • 2.4k
  • 3
  • 9