Search code examples
solanasolana-web3jsanchor-solana

How do i fetch the idl of any program deployed on solana mainnet by its program address?


I want to fetch the IDL that anchor normally generates for any deployed solana program by just its program address on the client side

How to do this?

UPDATE: My bad I didnt take the time to research this properly, you can use this line of code const idl = await fetchIdl(programId); to fetch the idl as the answer states


Solution

  • There's a function specifically made for that in the @project-serum/anchor package called fetchIdl, ie:

    const idl = await fetchIdl(programId);
    

    Check out its implementation if you like: https://github.com/project-serum/anchor/blob/8ffb22d936f0f6468d8f00a1e8a3c24b07e5490e/ts/src/program/index.ts#L324-L349