Get Program IDL Address

Get the address of the programs IDL

import { PublicKey } from '@solana/web3.js';

async function getIdlAddress(programId: PublicKey): Promise<PublicKey> {
    // First find base address (PDA with empty seeds)
    const [base] = PublicKey.findProgramAddressSync([], programId);

    // Then create address with seed
    return await PublicKey.createWithSeed(base, "anchor:idl", programId);
}

// Example usage
async function main() {
    const programId = new PublicKey('SQDS4ep65T869zMMBKyuUq6aD6EgTu8psMjkvj52pCf');
    const idlAddress = await getIdlAddress(programId);
    console.log('IDL Address:', idlAddress.toString());
}

main();