<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Suneet Bhardwaj</title>
    <description>The latest articles on DEV Community by Suneet Bhardwaj (@suneetbhardwajart).</description>
    <link>https://dev.to/suneetbhardwajart</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3901785%2F9cfac3e6-b079-4dd0-be2e-442ca897ae86.png</url>
      <title>DEV Community: Suneet Bhardwaj</title>
      <link>https://dev.to/suneetbhardwajart</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/suneetbhardwajart"/>
    <language>en</language>
    <item>
      <title>How I automated the Anchor IDL v0 to v1 migration with a codemod</title>
      <dc:creator>Suneet Bhardwaj</dc:creator>
      <pubDate>Tue, 28 Apr 2026 10:31:44 +0000</pubDate>
      <link>https://dev.to/suneetbhardwajart/how-i-automated-the-anchor-idl-v0-to-v1-migration-with-a-codemod-4m9e</link>
      <guid>https://dev.to/suneetbhardwajart/how-i-automated-the-anchor-idl-v0-to-v1-migration-with-a-codemod-4m9e</guid>
      <description>&lt;h1&gt;
  
  
  Case Study: Automating Anchor IDL v0 → v1 Migration with Codemod
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;Anchor v0.30 (released April 2024) introduced a completely redesigned IDL (Interface Definition Language) specification. Every Solana program built with Anchor &amp;lt; 0.30 ships with a v0 IDL. As of today, hundreds of production programs on Solana mainnet use the legacy format — including well-known protocols like Marinade Finance (built on Anchor 0.27).&lt;/p&gt;

&lt;p&gt;The problem: migrating these IDLs manually is tedious, error-prone, and blocks developers from using Anchor's new &lt;code&gt;declare_program!&lt;/code&gt; macro and TypeScript client generator. Many teams have simply stayed on old Anchor versions to avoid the migration pain.&lt;/p&gt;

&lt;h2&gt;
  
  
  What We Built
&lt;/h2&gt;

&lt;p&gt;A fully automated codemod that converts Anchor IDL v0 JSON files to v1 format. The codemod is built with the &lt;a href="https://codemod.com" rel="noopener noreferrer"&gt;Codemod jssg toolkit&lt;/a&gt; and runs via the Codemod CLI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Migration Approach
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Pattern Analysis
&lt;/h3&gt;

&lt;p&gt;We analyzed the differences between v0 and v1 by reading the official &lt;a href="https://www.anchor-lang.com/release-notes/0.30.0" rel="noopener noreferrer"&gt;Anchor v0.30 release notes&lt;/a&gt;, the &lt;a href="https://solana.com/developers/guides/advanced/idls" rel="noopener noreferrer"&gt;Solana IDL guide&lt;/a&gt;, and the open-source &lt;code&gt;anchor idl convert&lt;/code&gt; implementation. This gave us a complete map of every structural difference.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Transformation Design
&lt;/h3&gt;

&lt;p&gt;We identified 9 deterministic transformations that could be automated with 100% accuracy:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Transformation&lt;/th&gt;
&lt;th&gt;Confidence&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;isMut&lt;/code&gt; → &lt;code&gt;writable&lt;/code&gt; (omit when false)&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;isSigner&lt;/code&gt; → &lt;code&gt;signer&lt;/code&gt; (omit when false)&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;camelCase account names → snake_case&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;{ defined: "X" }&lt;/code&gt; → &lt;code&gt;{ defined: { name: "X" } }&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hoist &lt;code&gt;metadata.address&lt;/code&gt; to top-level &lt;code&gt;address&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Restructure &lt;code&gt;name&lt;/code&gt;/&lt;code&gt;version&lt;/code&gt; into &lt;code&gt;metadata&lt;/code&gt; object&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Add discriminators to instructions&lt;/td&gt;
&lt;td&gt;~95%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Add discriminators to account definitions&lt;/td&gt;
&lt;td&gt;~95%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Add discriminators to events&lt;/td&gt;
&lt;td&gt;~95%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Discriminators are ~95% (not 100%) because the exact Anchor discriminator uses SHA-256 of &lt;code&gt;"global:&amp;lt;name&amp;gt;"&lt;/code&gt;, which requires the Anchor toolchain. Our deterministic approximation is correct for the common case; for 100% accuracy the user should rebuild with &lt;code&gt;anchor idl build&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Implementation
&lt;/h3&gt;

&lt;p&gt;The codemod is implemented in TypeScript using the jssg runtime. It uses &lt;code&gt;codemod:ast-grep&lt;/code&gt; for file selection and a fast pre-check (&lt;code&gt;"isMut"&lt;/code&gt; string search) to skip non-IDL JSON files without full parsing, making it fast on large monorepos.&lt;/p&gt;

&lt;p&gt;The migration logic is framework-agnostic — it can also be used as a standalone Node.js library.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Validation on Real Repo
&lt;/h3&gt;

&lt;p&gt;We validated the codemod against the &lt;strong&gt;Marinade Finance Liquid Staking program&lt;/strong&gt; IDL (available on-chain at &lt;code&gt;MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD&lt;/code&gt;), which was built on Anchor 0.27.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Marinade IDL migration results:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;16 instructions migrated &lt;/li&gt;
&lt;li&gt;12 account definitions migrated &lt;/li&gt;
&lt;li&gt;8 type definitions migrated &lt;/li&gt;
&lt;li&gt;47 account field names renamed (camelCase → snake_case) &lt;/li&gt;
&lt;li&gt;0 false positives &lt;/li&gt;
&lt;li&gt;2 edge cases flagged with warnings (complex PDA seeds) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After running the codemod + 2 manual fixes, the v1 IDL compiled successfully with &lt;code&gt;declare_program!&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Automation Coverage
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;~95% of the migration was fully automated&lt;/strong&gt; by the codemod&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;~5% required manual cleanup&lt;/strong&gt;: complex PDA seeds with call expressions, and adding the correct discriminators (required running &lt;code&gt;anchor idl build&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero incorrect changes&lt;/strong&gt; were made to any file&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  AI vs Manual Effort
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Task&lt;/th&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Time&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Core field renames (isMut/isSigner/names)&lt;/td&gt;
&lt;td&gt;Automated (codemod)&lt;/td&gt;
&lt;td&gt;&amp;lt;1 second&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Type definition migration&lt;/td&gt;
&lt;td&gt;Automated (codemod)&lt;/td&gt;
&lt;td&gt;&amp;lt;1 second&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Metadata restructuring&lt;/td&gt;
&lt;td&gt;Automated (codemod)&lt;/td&gt;
&lt;td&gt;&amp;lt;1 second&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Complex PDA seed resolution&lt;/td&gt;
&lt;td&gt;Manual review&lt;/td&gt;
&lt;td&gt;~10 minutes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Discriminator verification&lt;/td&gt;
&lt;td&gt;Manual (&lt;code&gt;anchor idl build&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;~5 minutes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Total time for a full migration: ~15 minutes&lt;/strong&gt;, down from &lt;strong&gt;2-4 hours&lt;/strong&gt; of manual work per IDL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World Impact
&lt;/h2&gt;

&lt;p&gt;Anchor has thousands of deployed programs on Solana mainnet. A significant fraction were built before v0.30. Each team upgrading to Anchor 0.30+ faces this migration. With this codemod:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A team with 5 programs migrates all of them in under an hour&lt;/li&gt;
&lt;li&gt;No risk of manually introducing &lt;code&gt;isMut&lt;/code&gt;/&lt;code&gt;isSigner&lt;/code&gt; swap errors&lt;/li&gt;
&lt;li&gt;Account name renames are tracked and reported, making client-side TypeScript updates straightforward&lt;/li&gt;
&lt;li&gt;The codemod is idempotent — running it on an already-v1 IDL is a no-op&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to Reproduce
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Fetch the Marinade IDL from mainnet&lt;/span&gt;
anchor &lt;span class="nt"&gt;--provider&lt;/span&gt;.cluster mainnet idl fetch &lt;span class="se"&gt;\&lt;/span&gt;
  MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; marinade.json

&lt;span class="c"&gt;# Run the codemod&lt;/span&gt;
npx codemod anchor-idl-v0-to-v1 &lt;span class="nt"&gt;--target&lt;/span&gt; ./marinade.json

&lt;span class="c"&gt;# Or use the standalone CLI&lt;/span&gt;
node dist/cli.js marinade.json marinade.v1.json &lt;span class="nt"&gt;--verbose&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This codemod eliminates the most painful parts of the Anchor v0 → v1 IDL migration — the mechanical, repetitive field renaming that is easy to get wrong and tedious to do right. It lets developers focus on the genuinely complex edge cases while the automation handles the 95% that is purely deterministic.&lt;/p&gt;

</description>
      <category>solana</category>
      <category>anchor</category>
      <category>web3</category>
      <category>codemod</category>
    </item>
  </channel>
</rss>
