2

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

Anoushk
  • 551
  • 7
  • 20
  • Please try to ask a more specific question. Try to add the things you already tried or maybe errors of ways that didn't work for you. We would like to help you but not to take over your work – Y. Gherbi Mar 06 '22 at 23:05
  • 1
    @Y.Gherbi apologies for the lack of research,i havent used stackoverflow a lot to post questions so ill keep this in mind the next time, ill delete the question now, thanks for the feedback – Anoushk Mar 07 '22 at 11:38
  • ok i guess i cant delete the question so ill just update it, sorry again – Anoushk Mar 07 '22 at 11:41

1 Answers1

4

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

Jon C
  • 7,019
  • 10
  • 17
  • looks like i cant use this to fetch other people program that i didnt own, is there a way to fetch any program IDL? – kafinsalim Apr 20 '22 at 18:27
  • You sure can use this for programs that you don't own! There might be some other issue that you're seeing. – Jon C Apr 20 '22 at 19:13