solana-program / create-solana-program

pnpm create solana-program
Apache License 2.0
69 stars 9 forks source link

Can we autogenerate instruction creators and account decoders for an existing program? #30

Open mikemaccana opened 5 months ago

mikemaccana commented 5 months ago

The web3.js TP2 announment points to this repo with a 'here' link and the following text:

Instruction creators and account decoders can now be autogenerated for any program, including your own!

The README seems to imply generating clients for brand new projects, but can we use create-solana-program to generate clients for existing on-chain apps as the announcement states?

lorisleiva commented 5 months ago

Hey Mike,

Yes that's the plan.

We're already doing this for the following programs:

And planning to add many more to the list.

ronanyeah commented 5 months ago

Is there a way to avoid copy pasting the scripts contents? Such as an API like this:

create-solana-program generate:clients ./idl.json --js --output ./codegen"
lorisleiva commented 5 months ago

Hi @ronanyeah, sorry I'm not sure I understand the question. Are you saying you do not want the scripts folder to be present in the generated repository? If so, I'm not sure how the provided snippet of code helps with that.

mikemaccana commented 5 months ago

Thanks for answering @loris but I realise I should have been clearer:

can we use create-solana-program to generate clients for existing on-chain apps as the announcement states?

I meant to say: how can we we use create-solana-program to generate clients for existing on-chain apps? Eg what docs or examples exist for using create-solana-program in this way?

lorisleiva commented 5 months ago

Oh I see. No docs right now and it's on a case-by-case basis but we're using the following process:

  1. Run pnpm create solana-program my-existing-program --address MyExistingProgramAddress
  2. Follow the prompts and use these naming conventions.
  3. Replace the program folder with the existing program — or empty it and add idl.json inside for non-yet-migrated BPF programs.
  4. Make existing program use Shank if it's not already so we can generate an IDL from it.
  5. pnpm generate
mikemaccana commented 5 months ago

Thanks! I'm in the middle of trying to get instructor notes together for something but will try on one of our demo apps as soon as I can.