Menu

1 / 5

idl-codegen: typed TypeScript and Dart clients from an Anchor IDL

DEV Community: typescript·Abdeldjalil Chougui·about 21 hours ago
#tLjFsWWc
#devtotypescript#devto#dev#dart#program
Reading 0:00
15s threshold

An Anchor program describes itself in an IDL: its instructions, accounts, types, events, errors and PDA seeds. The program side is generated for you by Anchor's macros. The client side is where the hand work starts. Someone has to write the function that serializes the arguments in Borsh, puts the 8-byte discriminator in front, lists the accounts in the right order with the right signer and writable flags, and derives the PDAs from the same seeds as the program.

Writing that once is fine. Writing it twice, in TypeScript for the web app and in Dart for the Flutter app, means two copies that have to stay in sync with the program and with each other. A wrong byte in either one gives a transaction that fails on chain with an error that says little.

idl-codegen reads an Anchor IDL (0.30+ spec) and writes both clients. The README opens with a warning that belongs here too: the project is not audited . Generated clients build instructions and decode accounts; they do not sign or send anything.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.