<?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: Lymah</title>
    <description>The latest articles on DEV Community by Lymah (@lymah).</description>
    <link>https://dev.to/lymah</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1170961%2F98ca50d4-d70c-4fc3-a3fb-e4b6e74c149c.jpg</url>
      <title>DEV Community: Lymah</title>
      <link>https://dev.to/lymah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lymah"/>
    <language>en</language>
    <item>
      <title>Coming from Web2, Token-2022 taught me that some of the hardest bugs aren't failed transactions; they're successful transactions with incorrect outcomes.

Here are five mistakes I wish I'd known sooner.</title>
      <dc:creator>Lymah</dc:creator>
      <pubDate>Fri, 03 Jul 2026 19:32:06 +0000</pubDate>
      <link>https://dev.to/lymah/coming-from-web2-token-2022-taught-me-that-some-of-the-hardest-bugs-arent-failed-transactions-33of</link>
      <guid>https://dev.to/lymah/coming-from-web2-token-2022-taught-me-that-some-of-the-hardest-bugs-arent-failed-transactions-33of</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/lymah/5-token-2022-mistakes-i-made-so-you-dont-have-to-5e0b" class="crayons-story__hidden-navigation-link"&gt;5 Token-2022 Mistakes I Made So You Don't Have To&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/lymah" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1170961%2F98ca50d4-d70c-4fc3-a3fb-e4b6e74c149c.jpg" alt="lymah profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/lymah" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Lymah
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Lymah
                &lt;a href="/++"&gt;&lt;img alt="Subscriber" class="subscription-icon" src="https://assets.dev.to/assets/subscription-icon-805dfa7ac7dd660f07ed8d654877270825b07a92a03841aa99a1093bd00431b2.png"&gt;&lt;/a&gt;
              
              &lt;div id="story-author-preview-content-4011470" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/lymah" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1170961%2F98ca50d4-d70c-4fc3-a3fb-e4b6e74c149c.jpg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Lymah&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/lymah/5-token-2022-mistakes-i-made-so-you-dont-have-to-5e0b" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jun 30&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/lymah/5-token-2022-mistakes-i-made-so-you-dont-have-to-5e0b" id="article-link-4011470"&gt;
          5 Token-2022 Mistakes I Made So You Don't Have To
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/100daysofsolana"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;100daysofsolana&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/web3"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;web3&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/blockchain"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;blockchain&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/writing"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;writing&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/lymah/5-token-2022-mistakes-i-made-so-you-dont-have-to-5e0b" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/raised-hands-74b2099fd66a39f2d7eed9305ee0f4553df0eb7b4f11b01b6b1b499973048fe5.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;7&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/lymah/5-token-2022-mistakes-i-made-so-you-dont-have-to-5e0b#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              5&lt;span class="hidden s:inline"&gt;&amp;nbsp;comments&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            7 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>beginners</category>
      <category>blockchain</category>
      <category>debugging</category>
      <category>web3</category>
    </item>
    <item>
      <title>CPIs and PDA Signers: What I Built and What Actually Clicked</title>
      <dc:creator>Lymah</dc:creator>
      <pubDate>Fri, 03 Jul 2026 17:45:51 +0000</pubDate>
      <link>https://dev.to/lymah/cpis-and-pda-signers-what-i-built-and-what-actually-clicked-m6d</link>
      <guid>https://dev.to/lymah/cpis-and-pda-signers-what-i-built-and-what-actually-clicked-m6d</guid>
      <description>&lt;p&gt;I spent four days building programs that move SOL and tokens on Solana.&lt;br&gt;
Day 71 was a simple SOL transfer through a CPI. Day 74 was a mint&lt;br&gt;
whose authority belongs to a PDA with no private key — meaning nobody&lt;br&gt;
can ever mint outside the program's rules again.&lt;/p&gt;

&lt;p&gt;This post is what I learned between those two points, written for&lt;br&gt;
someone who understands Web2 backend code but has never written a&lt;br&gt;
Solana program.&lt;/p&gt;


&lt;h2&gt;
  
  
  The One Sentence Version
&lt;/h2&gt;

&lt;p&gt;A CPI is a program calling another program. A PDA signer is how a&lt;br&gt;
program proves it authorized that call without holding a private key.&lt;/p&gt;

&lt;p&gt;Everything else is details.&lt;/p&gt;


&lt;h2&gt;
  
  
  What CPIs Actually Are
&lt;/h2&gt;

&lt;p&gt;In Web2, your backend calls external APIs. A payment service, a&lt;br&gt;
messaging provider, a database driver. You pass credentials, the&lt;br&gt;
service does something, you get a result.&lt;/p&gt;

&lt;p&gt;On Solana, programs call other programs the same way — except the&lt;br&gt;
"credentials" are not an API key. They are either a wallet signature&lt;br&gt;
that propagated from the outer transaction, or a set of seeds that&lt;br&gt;
prove the calling program derived a specific address.&lt;/p&gt;

&lt;p&gt;The mechanism is &lt;code&gt;CpiContext&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;cpi_ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;CpiContext&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="py"&gt;.accounts.system_program&lt;/span&gt;&lt;span class="nf"&gt;.key&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="c1"&gt;// which program to call&lt;/span&gt;
    &lt;span class="n"&gt;Transfer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;                          &lt;span class="c1"&gt;// the accounts it needs&lt;/span&gt;
        &lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="py"&gt;.accounts.user&lt;/span&gt;&lt;span class="nf"&gt;.to_account_info&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="py"&gt;.accounts.vault&lt;/span&gt;&lt;span class="nf"&gt;.to_account_info&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;transfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cpi_ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// the instruction&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things: the program to call, the accounts it needs, the&lt;br&gt;
instruction to run. The &lt;code&gt;?&lt;/code&gt; makes it atomic — if the CPI fails,&lt;br&gt;
the whole transaction rolls back.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Two Cases
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Case 1: the wallet signs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When a user signs the outer transaction, that signature propagates&lt;br&gt;
automatically into any CPI that uses the wallet as an authority.&lt;br&gt;
You do not have to do anything special.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// User signed the tx → their wallet can authorize this CPI&lt;/span&gt;
&lt;span class="nf"&gt;transfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;CpiContext&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;system_program&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Transfer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;user_wallet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;recipient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}),&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is what I used on Day 71 (SOL transfer) and Day 72 (token mint).&lt;br&gt;
The program is a policy layer — it checks conditions, then forwards&lt;br&gt;
the call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Case 2: the program signs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the program needs to authorize something the user never signed&lt;br&gt;
for — like returning SOL from a vault or minting a reward — it uses&lt;br&gt;
PDA signer seeds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;signer_seeds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;]]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s"&gt;b"vault"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;user_key&lt;/span&gt;&lt;span class="nf"&gt;.as_ref&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;bump&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;]];&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;cpi_ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;CpiContext&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;system_program&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Transfer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;vault_pda&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;user_wallet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="nf"&gt;.with_signer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;signer_seeds&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ← this is the entire mechanism&lt;/span&gt;

&lt;span class="nf"&gt;transfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cpi_ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The runtime re-derives the PDA from those seeds and your program ID.&lt;br&gt;
If the result matches the account you passed in, the CPI is&lt;br&gt;
authorized. No private key. No human approval.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Vault: Deposit In, Program Signs Out
&lt;/h2&gt;

&lt;p&gt;Day 73 was the clearest demonstration. Two instructions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;deposit(amount)  → user wallet signs, SOL flows INTO the vault PDA
withdraw(amount) → program signs via seeds, SOL flows OUT of vault PDA
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The vault PDA is derived from &lt;code&gt;["vault", user_pubkey]&lt;/code&gt;. This means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every user has their own vault at a unique address&lt;/li&gt;
&lt;li&gt;The program can only withdraw to the user whose key is in the seeds&lt;/li&gt;
&lt;li&gt;Passing a different user's vault produces a seeds mismatch — rejected&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The test confirmed it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vault after deposit:  500000000 lamports
vault after withdraw: 0 lamports
✔ deposits, then the program signs to withdraw
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the failure test confirmed the protection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Impostor trying to withdraw from original user vault...
✗ FAILURE 2: AnchorError caused by account: vault.
Error Code: ConstraintSeeds. Error Number: 2006.
A seeds constraint was violated.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The seeds are the authorization policy. Not an ownership check in&lt;br&gt;
the handler — the derivation itself.&lt;/p&gt;


&lt;h2&gt;
  
  
  The PDA Mint Authority: Permanent Program Control
&lt;/h2&gt;

&lt;p&gt;Day 74 was the harder version. I created a Token-2022 mint, then&lt;br&gt;
transferred mint authority to a PDA:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;setAuthority&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;payer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;payer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;AuthorityType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MintTokens&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;mintAuthorityPda&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// ← PDA with no private key&lt;/span&gt;
  &lt;span class="p"&gt;[],&lt;/span&gt;
  &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this transaction, the only way to mint tokens is through&lt;br&gt;
the program's &lt;code&gt;mint_tokens&lt;/code&gt; instruction. No wallet can call&lt;br&gt;
&lt;code&gt;mintTo&lt;/code&gt; directly because no private key corresponds to the&lt;br&gt;
PDA address. The program is the only entity that can reconstruct&lt;br&gt;
the signer seeds at runtime.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Mint authority PDA: 8p6j3X6pBDVf4kzXcgk2VnnN3Jo18tJpjWqraMzguSbC
Minted base units:  500000000
✔ PDA signs the mint CPI — no human holds mint authority
Confirmed: only the program can mint — PDA has no private key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  What This Pattern Unlocks
&lt;/h2&gt;

&lt;p&gt;Every meaningful DeFi primitive on Solana uses this pattern:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Protocol type&lt;/th&gt;
&lt;th&gt;What the PDA controls&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Vault / escrow&lt;/td&gt;
&lt;td&gt;SOL or token release conditions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AMM&lt;/td&gt;
&lt;td&gt;Token pool balances&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lending protocol&lt;/td&gt;
&lt;td&gt;Collateral and liquidation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reward program&lt;/td&gt;
&lt;td&gt;When and how much to mint&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DAO treasury&lt;/td&gt;
&lt;td&gt;Fund distribution rules&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In every case, the rules live in the program. The PDA enforces&lt;br&gt;
that only the program can act. The seeds determine what the program&lt;br&gt;
can act on behalf of.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Three Failures That Made It Real
&lt;/h2&gt;

&lt;p&gt;I wrote a test suite that deliberately triggered three CPI failures:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure 1 — Insufficient funds:&lt;/strong&gt;&lt;br&gt;
Tried to withdraw 5 SOL from a vault holding 0.1 SOL.&lt;br&gt;
&lt;code&gt;✗ FAILURE 1: Simulation failed.&lt;/code&gt;&lt;br&gt;
The System Program rejected the transfer before it hit the chain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure 2 — Wrong signer (seeds mismatch):&lt;/strong&gt;&lt;br&gt;
An impostor wallet tried to withdraw from a different user's vault.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✗ FAILURE 2: ConstraintSeeds. Error Number: 2006.
A seeds constraint was violated.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The PDA derivation produced a different address. Rejected before&lt;br&gt;
the handler ran.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure 3 — Wrong program ID:&lt;/strong&gt;&lt;br&gt;
Passed a fake address instead of the System Program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✗ FAILURE 3: InvalidProgramId. Error Number: 3008.
Program ID was not as expected.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anchor validated the program address before the CPI could execute.&lt;/p&gt;

&lt;p&gt;All three caught cleanly. All three tell you exactly what went wrong.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I Would Tell Someone Starting This Week
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The wallet signature propagates automatically.&lt;/strong&gt;&lt;br&gt;
You do not need &lt;code&gt;.with_signer&lt;/code&gt; when the user's wallet is the&lt;br&gt;
authority. That is only for PDAs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;.with_signer&lt;/code&gt; is the entire PDA signing mechanism.&lt;/strong&gt;&lt;br&gt;
Everything else — the CpiContext, the accounts struct, the&lt;br&gt;
instruction call — is the same whether a wallet or a PDA signs.&lt;br&gt;
The only difference is that one line.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Store the bump on the account.&lt;/strong&gt;&lt;br&gt;
Compute it once in the &lt;code&gt;init&lt;/code&gt; instruction with &lt;code&gt;ctx.bumps.counter&lt;/code&gt;,&lt;br&gt;
store it as a field, reuse it on every subsequent call.&lt;br&gt;
Re-deriving it each time wastes compute.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The seeds are the authorization policy.&lt;/strong&gt;&lt;br&gt;
A vault derived from &lt;code&gt;["vault", user_pubkey]&lt;/code&gt; can only be drained&lt;br&gt;
to that user. You do not need an explicit ownership check — the&lt;br&gt;
derivation enforces it. If someone passes the wrong account, the&lt;br&gt;
seeds mismatch and Anchor rejects the transaction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;setAuthority&lt;/code&gt; is a point of no return.&lt;/strong&gt;&lt;br&gt;
Once you transfer mint authority to a PDA, no human can mint outside&lt;br&gt;
your program's rules. Make sure those rules are correct before you&lt;br&gt;
call it on mainnet.&lt;/p&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://solana.com/docs/core/cpi" rel="noopener noreferrer"&gt;Cross-Program Invocations — Solana docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://book.anchor-lang.com/anchor_in_depth/CPIs.html" rel="noopener noreferrer"&gt;CPI with signer seeds — Anchor book&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.rs/anchor-lang/latest/anchor_lang/system_program/fn.transfer.html" rel="noopener noreferrer"&gt;System Program transfer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.rs/anchor-spl/latest/anchor_spl/token_interface/fn.mint_to.html" rel="noopener noreferrer"&gt;Token Interface mint_to&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://solanacookbook.com/references/programs.html#how-to-do-cross-program-invocations" rel="noopener noreferrer"&gt;PDA signing — Solana cookbook&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Part of *&lt;/em&gt;#100DaysOfSolana*&lt;em&gt;. Building every day.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>100daysofcode</category>
      <category>anchor</category>
      <category>rust</category>
      <category>solana</category>
    </item>
    <item>
      <title>5 Token-2022 Mistakes I Made So You Don't Have To</title>
      <dc:creator>Lymah</dc:creator>
      <pubDate>Tue, 30 Jun 2026 14:46:47 +0000</pubDate>
      <link>https://dev.to/lymah/5-token-2022-mistakes-i-made-so-you-dont-have-to-5e0b</link>
      <guid>https://dev.to/lymah/5-token-2022-mistakes-i-made-so-you-dont-have-to-5e0b</guid>
      <description>&lt;p&gt;I spent two weeks building with Solana's Token-2022 program. I created fungible tokens, attached transfer fees, stacked interest on top, built&lt;br&gt;
soulbound credentials, and minted NFTs with on-chain metadata. Every one of those features worked — eventually. But before "eventually," each one had a moment where my output was wrong, my transaction failed, or my wallet balance moved in a direction I didn't expect.&lt;/p&gt;

&lt;p&gt;This post is about those moments. Not the happy path. The five mistakes&lt;br&gt;
that cost me the most time, and exactly what I had to understand to fix&lt;br&gt;
them.&lt;/p&gt;

&lt;p&gt;If you're coming from Web2 and you're curious about Solana tokens, this&lt;br&gt;
is the post I wish I'd had.&lt;/p&gt;


&lt;h2&gt;
  
  
  A Quick Mental Model Before We Start
&lt;/h2&gt;

&lt;p&gt;On Solana, a token isn't a smart contract. It's a &lt;strong&gt;mint account&lt;/strong&gt; — a small on-chain record that stores:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Total supply&lt;/li&gt;
&lt;li&gt;Decimal precision&lt;/li&gt;
&lt;li&gt;Who's allowed to create more tokens (the mint authority)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;Token-2022 program&lt;/strong&gt; (also called Token Extensions) is the&lt;br&gt;
upgraded version that lets you bolt additional behaviours onto a mint&lt;br&gt;
at creation time. Things like automatic transfer fees, interest accrual,&lt;br&gt;
and transfer restrictions.&lt;/p&gt;

&lt;p&gt;The catch: &lt;strong&gt;extensions are declared at mint creation and cannot be&lt;br&gt;
added later&lt;/strong&gt;. This is Mistake #3, and I'll come back to it. First,&lt;br&gt;
the one that burned me the most.&lt;/p&gt;


&lt;h2&gt;
  
  
  Mistake 1: The Base Units Trap
&lt;/h2&gt;

&lt;p&gt;When you create a Token-2022 mint with a transfer fee, you configure&lt;br&gt;
two numbers: the fee rate in basis points, and a maximum fee cap.&lt;/p&gt;

&lt;p&gt;The CLI command looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;spl-token create-token &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--program-id&lt;/span&gt; TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--transfer-fee-basis-points&lt;/span&gt; 100 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--transfer-fee-maximum-fee&lt;/span&gt; 5000 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--decimals&lt;/span&gt; 9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I ran this. I transferred 100 tokens at 1%. I expected 1 token to be&lt;br&gt;
withheld as a fee. Instead, the recipient received &lt;code&gt;99.999995&lt;/code&gt; tokens.&lt;br&gt;
The withheld amount was &lt;code&gt;0.000005&lt;/code&gt; — basically nothing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What went wrong:&lt;/strong&gt; &lt;code&gt;--transfer-fee-maximum-fee 5000&lt;/code&gt; is in &lt;em&gt;base&lt;br&gt;
units&lt;/em&gt;, not whole tokens. With 9 decimals, 5000 base units equals&lt;br&gt;
&lt;code&gt;0.000005&lt;/code&gt; whole tokens. The cap kicked in immediately and capped&lt;br&gt;
every fee at a fraction of a cent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fix:&lt;/strong&gt; Multiply by &lt;code&gt;10 ** decimals&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Wrong&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MAX_FEE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BigInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Right — 5000 whole tokens as the cap&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MAX_FEE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BigInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="nx"&gt;DECIMALS&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmso96x06hlz7g60jocf9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmso96x06hlz7g60jocf9.png" alt="Visual proof of the bug" width="792" height="546"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the most common Token-2022 gotcha. Every numeric parameter&lt;br&gt;
involving token amounts is in base units. The CLI doesn't warn you.&lt;br&gt;
The transaction succeeds. The number is just wrong.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F26f3893iiq14ms2z5d8i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F26f3893iiq14ms2z5d8i.png" alt="Shows the fix working" width="800" height="758"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdadqju1ej66h5yq1yd0l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdadqju1ej66h5yq1yd0l.png" alt="and Withheld: 1 tokens" width="637" height="233"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web2 equivalent:&lt;/strong&gt; Imagine a payment processor that charges fees in&lt;br&gt;
cents but you accidentally configured it in mills (1/10 of a cent).&lt;br&gt;
Everything "works" — the fee is just 10x smaller than you intended,&lt;br&gt;
and you only notice when you check the receipts.&lt;/p&gt;


&lt;h2&gt;
  
  
  Mistake 2: The Instruction Order Problem
&lt;/h2&gt;

&lt;p&gt;When creating a Token-2022 mint with extensions programmatically, you&lt;br&gt;
build a transaction with multiple instructions. The order matters — a lot.&lt;/p&gt;

&lt;p&gt;Here's the wrong order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Transaction&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;SystemProgram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createAccount&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="nf"&gt;createInitializeMintInstruction&lt;/span&gt;&lt;span class="p"&gt;(...),&lt;/span&gt;     &lt;span class="c1"&gt;// ← WRONG: mint before extensions&lt;/span&gt;
  &lt;span class="nf"&gt;createInitializeTransferFeeConfigInstruction&lt;/span&gt;&lt;span class="p"&gt;(...),&lt;/span&gt;
  &lt;span class="nf"&gt;createInitializeMetadataPointerInstruction&lt;/span&gt;&lt;span class="p"&gt;(...),&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This produces a cryptic error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: Transaction simulation failed:
Error processing Instruction 2: invalid account data for instruction
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The error points at instruction 2 (the transfer fee config), but the&lt;br&gt;
real problem is instruction 1 (the mint initialization). The mint is&lt;br&gt;
being initialized before the extension space is configured, so the&lt;br&gt;
runtime finds data in unexpected places.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fix:&lt;/strong&gt; Extension initializers must come &lt;em&gt;before&lt;/em&gt;&lt;br&gt;
&lt;code&gt;createInitializeMintInstruction&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Transaction&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;SystemProgram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createAccount&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="nf"&gt;createInitializeMetadataPointerInstruction&lt;/span&gt;&lt;span class="p"&gt;(...),&lt;/span&gt;   &lt;span class="c1"&gt;// extensions first&lt;/span&gt;
  &lt;span class="nf"&gt;createInitializeTransferFeeConfigInstruction&lt;/span&gt;&lt;span class="p"&gt;(...),&lt;/span&gt; &lt;span class="c1"&gt;// extensions first&lt;/span&gt;
  &lt;span class="nf"&gt;createInitializeMintInstruction&lt;/span&gt;&lt;span class="p"&gt;(...),&lt;/span&gt;              &lt;span class="c1"&gt;// mint LAST&lt;/span&gt;
  &lt;span class="nf"&gt;createInitializeInstruction&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;              &lt;span class="c1"&gt;// metadata after mint&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The mental model: extensions configure the account's memory layout.&lt;br&gt;
The mint instruction writes into that layout. If you write before you&lt;br&gt;
configure, you're writing into the wrong shape.&lt;/p&gt;


&lt;h2&gt;
  
  
  Mistake 3: Extensions Are Immutable After Creation
&lt;/h2&gt;

&lt;p&gt;Coming from Web2, I expected to be able to add features to a token&lt;br&gt;
after deploying it. In Rails you'd add a column with a migration.&lt;br&gt;
In Postgres you'd ALTER TABLE. On Token-2022, you can't.&lt;/p&gt;

&lt;p&gt;Extensions are baked into the mint account when it's created.&lt;br&gt;
The &lt;code&gt;getMintLen()&lt;/code&gt; function calculates how many bytes to allocate&lt;br&gt;
based on which extensions you declare. Once the account is allocated&lt;br&gt;
and the mint is initialized, that's the shape it has forever.&lt;/p&gt;

&lt;p&gt;I discovered this when I created a plain mint and then tried to add&lt;br&gt;
a transfer fee to it. There's no instruction for that. I had to&lt;br&gt;
create a new mint.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This is everything you can do with a mint you forgot to add&lt;/span&gt;
&lt;span class="c1"&gt;// extensions to: nothing. You create a new one.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;extensions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="nx"&gt;ExtensionType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;TransferFeeConfig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;// must declare ALL of these&lt;/span&gt;
  &lt;span class="nx"&gt;ExtensionType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;InterestBearingConfig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// at creation time&lt;/span&gt;
  &lt;span class="nx"&gt;ExtensionType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MetadataPointer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;    &lt;span class="c1"&gt;// you can't add them later&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mintLen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getMintLen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;extensions&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The practical consequence:&lt;/strong&gt; Design your token before you deploy it.&lt;br&gt;
Write down every extension you think you'll need. Add one or two you&lt;br&gt;
might need later. The cost of over-allocating is a slightly larger&lt;br&gt;
rent-exempt deposit. The cost of under-allocating is creating a new&lt;br&gt;
mint and migrating all your holders.&lt;/p&gt;


&lt;h2&gt;
  
  
  Mistake 4: Interest Is a View, Not a Balance
&lt;/h2&gt;

&lt;p&gt;This one is subtle and it confused me for longer than I'd like to admit.&lt;/p&gt;

&lt;p&gt;The Token-2022 &lt;code&gt;InterestBearingConfig&lt;/code&gt; extension stores an APR on the&lt;br&gt;
mint. As time passes, wallets and explorers show a growing balance.&lt;br&gt;
I assumed this meant new tokens were being minted. It doesn't.&lt;/p&gt;

&lt;p&gt;The raw on-chain balance never changes. What changes is the &lt;em&gt;displayed&lt;/em&gt;&lt;br&gt;
amount — a formula applied on the fly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UI Amount = raw_balance × e^(rate × elapsed_years)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I proved this by snapshotting the balance twice, 30 seconds apart,&lt;br&gt;
with no transactions in between:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Snapshot 1: 1,000,000.069191 tokens
Snapshot 2: 1,000,000.544703 tokens
Growth:     +0.475512 tokens in 30s
Raw balance: 1,000,000,000,000 base units (unchanged)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnk0bhu6uxvtp0pjuuwcu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnk0bhu6uxvtp0pjuuwcu.png" alt="Day 52 snapshots with no tx" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No transaction ran. The number grew because the display formula grew,&lt;br&gt;
not because any state changed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp2ic78lfrdzpqf0e0ipy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp2ic78lfrdzpqf0e0ipy.png" alt="Day 52 Mint" width="738" height="604"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why this matters:&lt;/strong&gt; Transfer fees operate on the &lt;em&gt;raw&lt;/em&gt; balance. Interest display operates on the &lt;em&gt;raw&lt;/em&gt; balance through a formula. They're completely independent. If you transfer tokens, the fee calculation uses the raw amount, not the interest-adjusted display amount. This is correct behavior, but if you're building a UI, you need to know which number to show and which to calculate with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web2 equivalent:&lt;/strong&gt; A savings account balance display that multiplies&lt;br&gt;
the raw database value by an interest factor before rendering. The&lt;br&gt;
database row doesn't change until you explicitly trigger a settlement.&lt;/p&gt;


&lt;h2&gt;
  
  
  Mistake 5: The Two-Layer Image Cache Problem
&lt;/h2&gt;

&lt;p&gt;When I updated my NFT's metadata URI to point at a new JSON file, the&lt;br&gt;
name changed immediately in Solana Explorer. The image took over an&lt;br&gt;
hour to update in wallets.&lt;/p&gt;

&lt;p&gt;These are two completely different layers:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;Where it lives&lt;/th&gt;
&lt;th&gt;Update speed&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Name, symbol, URI&lt;/td&gt;
&lt;td&gt;On-chain (mint account)&lt;/td&gt;
&lt;td&gt;Instant — one transaction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Image, attributes&lt;/td&gt;
&lt;td&gt;Off-chain (JSON at URI)&lt;/td&gt;
&lt;td&gt;Depends on wallet cache&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The on-chain URI is a pointer. The image it points at lives on an HTTP&lt;br&gt;
server. Wallets fetch that image when they first index the NFT and&lt;br&gt;
cache it aggressively — sometimes for hours, sometimes for days.&lt;/p&gt;

&lt;p&gt;When I ran this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Update the on-chain URI — instant&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sendAndConfirmTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Transaction&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;createUpdateFieldInstruction&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;programId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;updateAuthority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;field&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;uri&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://new-metadata.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fw38dfrnwb7avquubp4lz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fw38dfrnwb7avquubp4lz.png" alt="Shows on-chain instant update" width="800" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The URI changed on-chain immediately. But the wallet kept showing the&lt;br&gt;
old image because it had cached the previous fetch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fix for production:&lt;/strong&gt; Host your metadata and images on Arweave&lt;br&gt;
or IPFS with content-addressed URLs. Since the content hash is part&lt;br&gt;
of the URL, a changed image gets a new URL, which forces a fresh fetch.&lt;br&gt;
A mutable HTTP URL (like a GitHub Gist) means wallets might show stale&lt;br&gt;
content indefinitely.&lt;/p&gt;

&lt;p&gt;This is why serious NFT projects pay for permanent storage. The&lt;br&gt;
on-chain pointer is permanent. The thing it points at should be too.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I'd Tell Myself at the Start
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Always multiply by &lt;code&gt;10 ** decimals&lt;/code&gt;.&lt;/strong&gt; Every time. Without exception.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Extension initializers come before &lt;code&gt;createInitializeMintInstruction&lt;/code&gt;.&lt;/strong&gt; Burn this into your muscle memory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Design your token schema before you create the mint.&lt;/strong&gt; You can't migrate. You can only start over.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Interest is a display formula, not a ledger update.&lt;/strong&gt; Raw balance is truth. UI amount is interpretation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;On-chain metadata updates instantly. Off-chain images don't.&lt;/strong&gt; If you need fast image updates, use content-addressed storage.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  What I Actually Built
&lt;/h2&gt;

&lt;p&gt;Despite all of this, the extensions work beautifully once you&lt;br&gt;
understand them. By the end of Epoch 2 I had:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A fungible token with 1% transfer fees, harvested and withdrawn&lt;/li&gt;
&lt;li&gt;A stacked mint with both transfer fees and 50% APR interest&lt;/li&gt;
&lt;li&gt;A soulbound credential token that the runtime physically refuses to transfer&lt;/li&gt;
&lt;li&gt;An NFT with on-chain metadata, grouped into a collection&lt;/li&gt;
&lt;li&gt;Live metadata mutation — renaming an NFT mid-life in one transaction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of it built on Windows, without the spl-token CLI, using&lt;br&gt;
Node.js and @solana/spl-token directly. The mistakes above are&lt;br&gt;
the price of admission. The program is worth it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to Go From Here
&lt;/h2&gt;

&lt;p&gt;If you want to explore Token-2022 extensions yourself, the best&lt;br&gt;
starting points are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://solana.com/docs/tokens/extensions" rel="noopener noreferrer"&gt;Token Extensions overview&lt;/a&gt; — the canonical reference&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://solana.com/docs/tokens/extensions/transfer-fees" rel="noopener noreferrer"&gt;Transfer Fee extension&lt;/a&gt; — with the base units trap explained&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://solana.com/docs/tokens/extensions/interest-bearing-mint" rel="noopener noreferrer"&gt;Interest-Bearing extension&lt;/a&gt; — including the view vs balance distinction&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://solana.com/docs/tokens/extensions/metadata" rel="noopener noreferrer"&gt;Token Metadata extension&lt;/a&gt; — on-chain vs off-chain metadata&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of the code in this post was written in Node.js on Windows — no&lt;br&gt;
CLI available, every extension built programmatically using&lt;br&gt;
&lt;code&gt;@solana/web3.js&lt;/code&gt; and &lt;code&gt;@solana/spl-token&lt;/code&gt;. If I could do it without&lt;br&gt;
the CLI, so can you.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This post is part of *&lt;/em&gt;#100DaysOfSolana*&lt;em&gt;. I've been building on&lt;br&gt;
Solana every day for over two months. If you're starting out, the&lt;br&gt;
mistakes above will save you hours. If you're experienced and I got&lt;br&gt;
something wrong, tell me in the comments — I'm still learning too.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>100daysofsolana</category>
      <category>web3</category>
      <category>blockchain</category>
      <category>writing</category>
    </item>
    <item>
      <title>What I Learned About PDAs in a Week of Building on Solana</title>
      <dc:creator>Lymah</dc:creator>
      <pubDate>Sat, 27 Jun 2026 16:37:12 +0000</pubDate>
      <link>https://dev.to/lymah/what-i-learned-about-pdas-in-a-week-of-building-on-solana-4n51</link>
      <guid>https://dev.to/lymah/what-i-learned-about-pdas-in-a-week-of-building-on-solana-4n51</guid>
      <description>&lt;p&gt;I spent a week building a counter program in Anchor. By the end, every&lt;br&gt;
user had their own account, a global config singleton controlled whether&lt;br&gt;
new counters could be created, and a close instruction returned the rent&lt;br&gt;
deposit back to the wallet. None of that would have been possible without&lt;br&gt;
Program Derived Addresses.&lt;/p&gt;

&lt;p&gt;This post is what I wish someone had handed me on day one.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Problem PDAs Solve
&lt;/h2&gt;

&lt;p&gt;On Solana, programs are stateless. If your program needs to remember&lt;br&gt;
something, a user's score, a vault balance, a config flag, it needs&lt;br&gt;
a dedicated account to store it in. And that account needs an address&lt;br&gt;
your program can find again later, without the client having to pass&lt;br&gt;
around a randomly generated keypair.&lt;/p&gt;

&lt;p&gt;PDAs are that address. Deterministic. Derivable from inputs your&lt;br&gt;
program already knows. No private key required.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Mental Model
&lt;/h2&gt;

&lt;p&gt;Here is the Web2 analogy that helped me most:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A PDA is like a database primary key you can compute from the&lt;br&gt;
row's logical identity.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In Postgres, if you want one row per user, you use &lt;code&gt;user_id&lt;/code&gt; as the&lt;br&gt;
primary key. You never store the key separately — you derive it from&lt;br&gt;
who is asking. PDAs work the same way. You feed in a list of seeds&lt;br&gt;
(bytes that describe the identity of the thing you want to store) plus&lt;br&gt;
your program's ID, and you get back a deterministic address.&lt;/p&gt;

&lt;p&gt;Every time you run the derivation with the same inputs, you get the&lt;br&gt;
same address. That is the whole point.&lt;/p&gt;

&lt;p&gt;Where the analogy breaks: the address may or may not have an account&lt;br&gt;
at it yet. Deriving a PDA does not create anything on the chain. It just&lt;br&gt;
computes a public key. The account gets created when your program runs&lt;br&gt;
an instruction with the &lt;code&gt;init&lt;/code&gt; constraint, and that creation costs&lt;br&gt;
rent, paid by whoever is signing the transaction.&lt;/p&gt;

&lt;p&gt;One more thing the analogy misses: the program ID is baked into the&lt;br&gt;
derivation. The same seeds run through a different program produce a&lt;br&gt;
completely different address. This means only your program can&lt;br&gt;
predictably derive and sign for its own PDAs. No other program can&lt;br&gt;
guess them or collide with them accidentally.&lt;/p&gt;


&lt;h2&gt;
  
  
  Anatomy of a Derivation
&lt;/h2&gt;

&lt;p&gt;Here is the accounts struct from my counter program, exactly as it&lt;br&gt;
appears in &lt;code&gt;lib.rs&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[derive(Accounts)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;InitCounter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;#[account(&lt;/span&gt;
        &lt;span class="nd"&gt;init,&lt;/span&gt;
        &lt;span class="nd"&gt;payer&lt;/span&gt; &lt;span class="nd"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;user,&lt;/span&gt;
        &lt;span class="nd"&gt;space&lt;/span&gt; &lt;span class="nd"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="nd"&gt;Counter::INIT_SPACE,&lt;/span&gt;
        &lt;span class="nd"&gt;seeds&lt;/span&gt; &lt;span class="nd"&gt;=&lt;/span&gt; &lt;span class="err"&gt;[&lt;/span&gt;&lt;span class="s"&gt;b"counter"&lt;/span&gt;&lt;span class="nd"&gt;,&lt;/span&gt; &lt;span class="nd"&gt;user&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nd"&gt;key()&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nd"&gt;as_ref()]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;bump&lt;/span&gt;
    &lt;span class="p"&gt;)]&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Account&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nd"&gt;#[account(mut)]&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Signer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;system_program&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Program&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me walk through every piece.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;seeds = [b"counter", user.key().as_ref()]&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The seed array is the input to the hash. It has two parts here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;b"counter"&lt;/code&gt; — a static byte string that acts as a namespace.
It ensures this address is clearly "a counter account," not
something else.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;user.key().as_ref()&lt;/code&gt; — the signer's public key as bytes.
This is what makes the address unique per user.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Under the hood, Anchor runs &lt;code&gt;sha256(seeds + program_id + bump)&lt;/code&gt;&lt;br&gt;
and checks whether the result lands on the ed25519 elliptic curve.&lt;br&gt;
If it does, it decrements the bump and tries again. The first result&lt;br&gt;
that lands &lt;em&gt;off&lt;/em&gt; the curve is returned as the canonical PDA. Off-curve&lt;br&gt;
means no private key can produce it, which means only your program&lt;br&gt;
can sign for it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;bump&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The bump is a single byte (0–255) appended to the hash input.&lt;br&gt;
&lt;code&gt;PublicKey.findProgramAddressSync&lt;/code&gt; starts at 255 and counts down&lt;br&gt;
until it finds an off-curve result. The first bump that works is&lt;br&gt;
the canonical bump. Anchor computes it for you and stores it in&lt;br&gt;
&lt;code&gt;ctx.bumps.counter&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;init&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This constraint tells Anchor to create the account at the derived&lt;br&gt;
address if it doesn't already exist. It makes a CPI (cross-program&lt;br&gt;
invocation) to the System Program, which allocates the bytes and&lt;br&gt;
transfers the rent-exempt deposit from the payer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;space = 8 + Counter::INIT_SPACE&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The 8 bytes are Anchor's discriminator — a prefix stamped on every&lt;br&gt;
account so the program can later verify "yes, this is a Counter&lt;br&gt;
account, not something else." &lt;code&gt;Counter::INIT_SPACE&lt;/code&gt; is computed&lt;br&gt;
automatically by the &lt;code&gt;#[derive(InitSpace)]&lt;/code&gt; macro.&lt;/p&gt;


&lt;h2&gt;
  
  
  Why the Seeds Matter
&lt;/h2&gt;

&lt;p&gt;The seeds are your access control policy.&lt;/p&gt;

&lt;p&gt;My counter program uses &lt;code&gt;[b"counter", user.key().as_ref()]&lt;/code&gt;. That&lt;br&gt;
means every signer gets their own PDA. Alice's counter and Bob's&lt;br&gt;
counter live at completely different addresses, derived independently.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Alice's counter&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;alicePda&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;PublicKey&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findProgramAddressSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;counter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;alice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBuffer&lt;/span&gt;&lt;span class="p"&gt;()],&lt;/span&gt;
  &lt;span class="nx"&gt;programId&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Bob's counter&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;bobPda&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;PublicKey&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findProgramAddressSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;counter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;bob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBuffer&lt;/span&gt;&lt;span class="p"&gt;()],&lt;/span&gt;
  &lt;span class="nx"&gt;programId&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;alicePda&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bobPda&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// false — always&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compare that to the config singleton in my program, which uses&lt;br&gt;
&lt;code&gt;[b"config"]&lt;/code&gt; — no wallet in the seeds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Same address for every caller&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;configFromAlice&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;PublicKey&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findProgramAddressSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;config&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt; &lt;span class="nx"&gt;programId&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;configFromBob&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;PublicKey&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findProgramAddressSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;config&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt; &lt;span class="nx"&gt;programId&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;configFromAlice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;configFromBob&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// true — always&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One address. Every caller computes the same thing. That's exactly what&lt;br&gt;
you want for a global config — one row at the top of the database that&lt;br&gt;
everyone reads from.&lt;/p&gt;

&lt;p&gt;Use the wrong pattern and you get disasters. If I had written my&lt;br&gt;
counter as &lt;code&gt;[b"counter"]&lt;/code&gt;, the first user to call &lt;code&gt;init_counter&lt;/code&gt;&lt;br&gt;
would own the only counter that can ever exist. Everyone else would&lt;br&gt;
get "account already in use."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One byte changes everything:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;["counter",  walletA] → E4C9RStxbiweqVv7rHM88HgzWNhcCibTHWtGn7HrowjM

["counters", walletA] → AoaX8ntGs9tj7b96pbMcPHD822X8tEqRAg7p48VgdcmZ

["counter\0",walletA] → Es37q2wXjeYPkGhfcn4qnB3Uu167VmbtKUVaQ8i87LTm

["Counter",  walletA] → 2WSX2ScZwFgDDYZWkspqrCHTWnSsGoXquH425a2zgsWy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same program, same wallet, four completely different addresses.&lt;br&gt;
There is no "close enough" in PDA derivation.&lt;/p&gt;


&lt;h2&gt;
  
  
  What the Bump Buys You
&lt;/h2&gt;

&lt;p&gt;The bump is not magic. It is just the first byte value (starting from&lt;br&gt;
255, counting down) that pushed the hash result off the ed25519 curve.&lt;br&gt;
Off-curve means no private key exists at that point. No private key&lt;br&gt;
means no human can sign for it. Only your program can — by providing&lt;br&gt;
the same seeds plus bump to the runtime when it needs to authorize&lt;br&gt;
something.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Always store the bump on the account:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[account]&lt;/span&gt;
&lt;span class="nd"&gt;#[derive(InitSpace)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Counter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Pubkey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;bump&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// ← store this&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;init_counter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;InitCounter&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="py"&gt;.accounts.counter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="py"&gt;.bump&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="py"&gt;.bumps.counter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// ← Anchor gives it to you here&lt;/span&gt;
    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(())&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then on subsequent instructions, pass it back instead of re-deriving:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[account(&lt;/span&gt;
    &lt;span class="nd"&gt;mut,&lt;/span&gt;
    &lt;span class="nd"&gt;seeds&lt;/span&gt; &lt;span class="nd"&gt;=&lt;/span&gt; &lt;span class="err"&gt;[&lt;/span&gt;&lt;span class="s"&gt;b"counter"&lt;/span&gt;&lt;span class="nd"&gt;,&lt;/span&gt; &lt;span class="nd"&gt;user&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nd"&gt;key()&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nd"&gt;as_ref()]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;bump&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="py"&gt;.bump&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// ← use the stored bump, not bump alone&lt;/span&gt;
&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;'info&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Counter&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Re-deriving the bump on every call is unnecessary compute. Storing&lt;br&gt;
it once and reusing it is free. Anchor's &lt;code&gt;bump&lt;/code&gt; constraint (without&lt;br&gt;
&lt;code&gt;= counter.bump&lt;/code&gt;) re-derives every time. &lt;code&gt;bump = counter.bump&lt;/code&gt;&lt;br&gt;
uses the stored value. Use the stored value.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Full Lifecycle
&lt;/h2&gt;

&lt;p&gt;My week in four steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Derive the address (off-chain)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;counterPda&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;PublicKey&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findProgramAddressSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;counter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBuffer&lt;/span&gt;&lt;span class="p"&gt;()],&lt;/span&gt;
  &lt;span class="nx"&gt;programId&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// counterPda is an address. Nothing on the chain yet.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Initialize the account (init instruction)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;init&lt;/code&gt; constraint on the Anchor accounts struct creates the&lt;br&gt;
account at the derived address, allocates the right number of bytes,&lt;br&gt;
and funds the rent-exempt deposit from the payer. After this&lt;br&gt;
transaction, the account exists on the chain with your program as its&lt;br&gt;
owner.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Mutate data (subsequent instructions)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every later instruction re-derives the PDA from the seeds and&lt;br&gt;
validates that it matches the account passed in. The &lt;code&gt;seeds&lt;/code&gt; and &lt;code&gt;bump&lt;/code&gt;&lt;br&gt;
Constraints do this automatically. Your handler just reads and writes&lt;br&gt;
the fields.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Close the account (close instruction)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Closing a PDA is not like dropping a table row. It is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Transfer all lamports to the destination wallet&lt;/li&gt;
&lt;li&gt;Zero out the account data&lt;/li&gt;
&lt;li&gt;The runtime removes the account from state at the end of the
transaction (a zero-lamport account cannot persist)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In Anchor, one constraint does all of this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[account(&lt;/span&gt;
    &lt;span class="nd"&gt;mut,&lt;/span&gt;
    &lt;span class="nd"&gt;close&lt;/span&gt; &lt;span class="nd"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;user,&lt;/span&gt;    &lt;span class="c1"&gt;// ← drains lamports to user, zeros data&lt;/span&gt;
    &lt;span class="nd"&gt;seeds&lt;/span&gt; &lt;span class="nd"&gt;=&lt;/span&gt; &lt;span class="err"&gt;[&lt;/span&gt;&lt;span class="s"&gt;b"counter"&lt;/span&gt;&lt;span class="nd"&gt;,&lt;/span&gt; &lt;span class="nd"&gt;user&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nd"&gt;key()&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nd"&gt;as_ref()]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;bump&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="py"&gt;.bump&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;has_one&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;'info&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Counter&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The rent deposit comes back to the wallet. The account disappears.&lt;br&gt;
&lt;code&gt;getAccountInfo&lt;/code&gt; returns &lt;code&gt;null&lt;/code&gt; on the next call.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I Would Tell Past Me
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The program ID is part of the derivation.&lt;/strong&gt; The same seeds in a&lt;br&gt;
different program produce a completely different address. This is a&lt;br&gt;
feature — your PDAs belong to your program and no other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PDAs cannot sign transactions themselves.&lt;/strong&gt; Only programs can sign&lt;br&gt;
on a PDA's behalf, by providing the seeds and bump to the runtime as&lt;br&gt;
"signer seeds." This is how your program authorizes CPIs from a PDA&lt;br&gt;
it owns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;init_if_needed&lt;/code&gt; is a footgun.&lt;/strong&gt; It initializes the account if it&lt;br&gt;
doesn't exist, and silently does nothing if it does. That sounds&lt;br&gt;
convenient until a caller reuses it to overwrite an account they&lt;br&gt;
don't own. Use &lt;code&gt;init&lt;/code&gt; when you mean "create exactly once."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The seeds enforce access control, not just naming.&lt;/strong&gt; When Anchor&lt;br&gt;
validates a PDA constraint, it re-derives the expected address from&lt;br&gt;
the seeds and compares it to what you passed in. If someone passes&lt;br&gt;
the wrong account, the derivation produces a different address, and&lt;br&gt;
the transaction is rejected before your handler runs. You do not need&lt;br&gt;
an explicit ownership check — the seeds are the ownership check.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Design your seed scheme before you write any code.&lt;/strong&gt; You cannot&lt;br&gt;
change the seeds after deployment. A counter keyed by&lt;br&gt;
&lt;code&gt;[b"counter", user.key()]&lt;/code&gt; and one keyed by&lt;br&gt;
&lt;code&gt;[b"user_counter", user.key()]&lt;/code&gt; are in completely different address&lt;br&gt;
spaces. Pick once, keep forever.&lt;/p&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://solana.com/docs/core/pda" rel="noopener noreferrer"&gt;Program Derived Addresses — Solana docs&lt;/a&gt;
The canonical reference for how PDAs are derived and what
guarantees you actually get.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.anchor-lang.com/docs/pdas" rel="noopener noreferrer"&gt;PDAs in Anchor&lt;/a&gt;
The seed and bump constraint syntax, with examples.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.anchor-lang.com/docs/account-constraints" rel="noopener noreferrer"&gt;Anchor account constraints reference&lt;/a&gt;
Full list of constraints including &lt;code&gt;init&lt;/code&gt;, &lt;code&gt;has_one&lt;/code&gt;, &lt;code&gt;seeds&lt;/code&gt;,
&lt;code&gt;bump&lt;/code&gt;, &lt;code&gt;close&lt;/code&gt;, and &lt;code&gt;constraint&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Lymah123/100-days-of-solana" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The full counter program from this arc is available in my&lt;br&gt;
100 Days of Solana repo. If anything in this post is wrong,&lt;br&gt;
leave a comment — I'm still learning.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This post is part of *&lt;/em&gt;#100DaysOfSolana*&lt;em&gt;. Building on Solana&lt;br&gt;
every day.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rust</category>
      <category>solana</category>
      <category>anchor</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How I Built a Counter Program in Anchor and Learned to Trust My Tests</title>
      <dc:creator>Lymah</dc:creator>
      <pubDate>Sat, 20 Jun 2026 18:54:21 +0000</pubDate>
      <link>https://dev.to/lymah/how-i-built-a-counter-program-in-anchor-and-learned-to-trust-my-tests-1akg</link>
      <guid>https://dev.to/lymah/how-i-built-a-counter-program-in-anchor-and-learned-to-trust-my-tests-1akg</guid>
      <description>&lt;p&gt;I spent a week building a counter program in Anchor — the Rust framework&lt;br&gt;
for writing Solana programs. By the end I had two instructions, one&lt;br&gt;
authorization constraint, and a test suite I could actually trust. Here&lt;br&gt;
is what I built, how I tested it, and the moment I proved the tests&lt;br&gt;
were real.&lt;/p&gt;


&lt;h2&gt;
  
  
  Start Here: The Accounts Struct
&lt;/h2&gt;

&lt;p&gt;If you come from Web2, this is the part that looks the strangest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[derive(Accounts)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Initialize&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;#[account(&lt;/span&gt;
        &lt;span class="nd"&gt;init,&lt;/span&gt;
        &lt;span class="nd"&gt;payer&lt;/span&gt; &lt;span class="nd"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;authority,&lt;/span&gt;
        &lt;span class="nd"&gt;space&lt;/span&gt; &lt;span class="nd"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="nd"&gt;Counter::INIT_SPACE,&lt;/span&gt;
    &lt;span class="nd"&gt;)]&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Account&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nd"&gt;#[account(mut)]&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Signer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;system_program&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Program&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a Web2 backend, your handler receives a request object and talks&lt;br&gt;
to a database. On Solana, there is no database; there are accounts.&lt;br&gt;
Every account your instruction needs to read or write must be declared&lt;br&gt;
upfront, before the handler runs. Anchor validates them before your&lt;br&gt;
code ever executes.&lt;/p&gt;

&lt;p&gt;Here is what each field does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;counter&lt;/code&gt;&lt;/strong&gt; — the account being created. The &lt;code&gt;init&lt;/code&gt; constraint
tells Anchor to make a CPI to the System Program, allocate
&lt;code&gt;8 + Counter::INIT_SPACE&lt;/code&gt; bytes, and fund it from &lt;code&gt;authority&lt;/code&gt;.
The &lt;code&gt;8&lt;/code&gt; is for the discriminator Anchor stamps on every account
so the program can later verify "this is mine."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;authority&lt;/code&gt;&lt;/strong&gt; — the wallet signing and paying for the transaction.
&lt;code&gt;mut&lt;/code&gt; because its SOL balance is decreasing to fund the new account.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;system_program&lt;/code&gt;&lt;/strong&gt; — required any time you create accounts.
Anchor checks that the address matches the real System Program.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The accounts struct is the schema. The handler is the logic.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Handlers
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="py"&gt;.accounts.counter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="py"&gt;.authority&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="py"&gt;.accounts.authority&lt;/span&gt;&lt;span class="nf"&gt;.key&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="py"&gt;.count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(())&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;ctx.accounts&lt;/code&gt; gives you typed access to every account declared in&lt;br&gt;
the struct. The handler is short because Anchor already did the hard&lt;br&gt;
work: allocating the account, checking the signer, paying the rent.&lt;br&gt;
Your code just sets the initial values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="py"&gt;.accounts.counter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="py"&gt;.count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="py"&gt;.count&lt;/span&gt;
        &lt;span class="nf"&gt;.checked_add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;.ok_or&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;error!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;ErrorCode&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;ArithmeticOverflow&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(())&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The accounts struct for &lt;code&gt;increment&lt;/code&gt; has a constraint worth paying&lt;br&gt;
attention to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[derive(Accounts)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Increment&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;#[account(mut,&lt;/span&gt; &lt;span class="nd"&gt;has_one&lt;/span&gt; &lt;span class="nd"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;authority)]&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Account&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Signer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;has_one = authority&lt;/code&gt; tells Anchor: before this handler runs, check&lt;br&gt;
that &lt;code&gt;counter.authority == authority.key()&lt;/code&gt;. If the wallet signing&lt;br&gt;
the transaction does not match the wallet stored on the counter,&lt;br&gt;
the transaction is rejected. My handler never sees a bad caller —&lt;br&gt;
the constraint rejects them first.&lt;/p&gt;

&lt;p&gt;This is the Solana equivalent of a 403 check, but it is declarative&lt;br&gt;
and enforced by the runtime. There is no application layer to&lt;br&gt;
accidentally bypass.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Tests
&lt;/h2&gt;

&lt;p&gt;I used &lt;a href="https://github.com/LiteSVM/litesvm" rel="noopener noreferrer"&gt;LiteSVM&lt;/a&gt; — an in-process&lt;br&gt;
Solana VM that runs your compiled program against a fresh ledger in&lt;br&gt;
milliseconds. No devnet, no flakiness, no airdrop required.&lt;/p&gt;

&lt;h3&gt;
  
  
  Happy path
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[test]&lt;/span&gt;
&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;initialize_then_increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;svm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;LiteSVM&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="c1"&gt;// ... load program, airdrop, create keypairs ...&lt;/span&gt;

    &lt;span class="n"&gt;svm&lt;/span&gt;&lt;span class="nf"&gt;.send_transaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;init_tx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;svm&lt;/span&gt;&lt;span class="nf"&gt;.send_transaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inc_tx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;svm&lt;/span&gt;&lt;span class="nf"&gt;.get_account&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;counter_kp&lt;/span&gt;&lt;span class="nf"&gt;.pubkey&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;parsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;try_deserialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="py"&gt;.data&lt;/span&gt;&lt;span class="nf"&gt;.as_slice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

   &lt;span class="nd"&gt;assert_eq!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parsed&lt;/span&gt;&lt;span class="py"&gt;.count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="nd"&gt;assert_eq!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parsed&lt;/span&gt;&lt;span class="py"&gt;.authority&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;authority&lt;/span&gt;&lt;span class="nf"&gt;.pubkey&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This test would fail if &lt;code&gt;increment&lt;/code&gt; stored the wrong number, or if&lt;br&gt;
&lt;code&gt;initialize&lt;/code&gt; set the wrong authority. It proves both instructions&lt;br&gt;
work correctly together.&lt;/p&gt;

&lt;h3&gt;
  
  
  Failure path
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[test]&lt;/span&gt;
&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;increment_fails_when_wrong_authority_signs&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// authority_a creates the counter&lt;/span&gt;
    &lt;span class="n"&gt;svm&lt;/span&gt;&lt;span class="nf"&gt;.send_transaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;init_tx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"initialize should succeed"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// authority_b tries to increment it&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;bad_tx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;build_increment_tx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;svm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;program_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;authority_b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="nf"&gt;.pubkey&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;svm&lt;/span&gt;&lt;span class="nf"&gt;.send_transaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bad_tx&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nd"&gt;assert!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="nf"&gt;.is_err&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="s"&gt;"increment should fail when signed by the wrong authority"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This test would fail if I removed or weakened the &lt;code&gt;has_one = authority&lt;/code&gt;&lt;br&gt;
constraint. It proves the gate is real, not just assumed.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Experiment That Made the Tests Real
&lt;/h2&gt;

&lt;p&gt;A passing test suite is a story. The question is whether it tells the&lt;br&gt;
truth.&lt;/p&gt;

&lt;p&gt;On the last day of the week I planted bugs on purpose, one at a time,&lt;br&gt;
and watched the suite catch them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The most instructive experiment:&lt;/strong&gt; I changed &lt;code&gt;checked_add(1)&lt;/code&gt; to&lt;br&gt;
&lt;code&gt;checked_add(2)&lt;/code&gt; in the increment handler. The transaction still&lt;br&gt;
succeeded — no error, no panic. But the stored value was wrong.&lt;/p&gt;

&lt;p&gt;The test output:&lt;br&gt;
test initialize_then_increment ... FAILED&lt;br&gt;
thread panicked at:&lt;/p&gt;

&lt;p&gt;assertion &lt;code&gt;left == right&lt;/code&gt; failed&lt;br&gt;
left: 1&lt;br&gt;
right: 2&lt;/p&gt;

&lt;p&gt;One character change in production code. One specific failure with a&lt;br&gt;
specific line number pointing exactly at the assertion that caught it.&lt;br&gt;
That is what assertions are for.&lt;/p&gt;

&lt;p&gt;Then I removed the &lt;code&gt;has_one = authority&lt;/code&gt; constraint entirely. The&lt;br&gt;
happy-path test stayed green — it uses the correct authority. But:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;test increment_fails_when_wrong_authority_signs ... FAILED&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;increment should fail when signed by the wrong authority&lt;/p&gt;

&lt;p&gt;The wrong-signer transaction now succeeded, and the test that expected&lt;br&gt;
a rejection panicked. Without that failure test, I would have silently&lt;br&gt;
shipped a program that lets anyone increment anyone else's counter.&lt;br&gt;
The negative test is the only reason I would have known.&lt;/p&gt;

&lt;p&gt;Both times I put the code back, ran the suite, and got green. The&lt;br&gt;
suite told the truth both times.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I Would Build Next
&lt;/h2&gt;

&lt;p&gt;The counter account in this program lives at a random keypair's&lt;br&gt;
address. That means the client has to remember which keypair holds&lt;br&gt;
which user's counter — messy in practice. The natural next step is&lt;br&gt;
&lt;strong&gt;Program Derived Addresses (PDAs)&lt;/strong&gt;: deterministic addresses derived&lt;br&gt;
from the user's wallet and a seed string, so any client can find any&lt;br&gt;
user's counter without storing a keypair.&lt;/p&gt;

&lt;p&gt;After that: a &lt;code&gt;decrement&lt;/code&gt; instruction, a &lt;code&gt;reset&lt;/code&gt; instruction, and&lt;br&gt;
then connecting the program to a TypeScript client so it can run&lt;br&gt;
on devnet with a real wallet.&lt;/p&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.anchor-lang.com/" rel="noopener noreferrer"&gt;Anchor framework&lt;/a&gt; — the framework
used throughout&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.anchor-lang.com/docs/account-constraints" rel="noopener noreferrer"&gt;Anchor account constraints reference&lt;/a&gt;
— full list of constraints including &lt;code&gt;has_one&lt;/code&gt;, &lt;code&gt;init&lt;/code&gt;, &lt;code&gt;mut&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/LiteSVM/litesvm" rel="noopener noreferrer"&gt;LiteSVM&lt;/a&gt; — the in-process
test harness&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://solana.com/docs" rel="noopener noreferrer"&gt;Solana docs&lt;/a&gt; — accounts model primer&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;This post is part of *&lt;/em&gt;#100DaysOfSolana*&lt;em&gt;. Building on Solana every&lt;br&gt;
day — follow along or jump in any time.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>solana</category>
      <category>rust</category>
      <category>anchor</category>
      <category>100daysofsolana</category>
    </item>
    <item>
      <title>Three Token-2022 Mints in One Week: Fees, Yield, and Soulbound</title>
      <dc:creator>Lymah</dc:creator>
      <pubDate>Sat, 13 Jun 2026 16:30:17 +0000</pubDate>
      <link>https://dev.to/lymah/three-token-2022-mints-in-one-week-fees-yield-and-soulbound-1nn0</link>
      <guid>https://dev.to/lymah/three-token-2022-mints-in-one-week-fees-yield-and-soulbound-1nn0</guid>
      <description>&lt;p&gt;If you come from Web2, you probably think of a token as a number in a database that moves around when people transact. On Solana, the original SPL Token program is exactly that. Token-2022 is the upgrade — and it lets you bolt behaviors directly onto the mint itself, the way you would add middleware to a payment pipeline, except the middleware lives inside the asset and cannot be bypassed.&lt;/p&gt;

&lt;p&gt;This week I shipped three different mints on Solana devnet, each&lt;br&gt;
demonstrating a different Token-2022 extension. Here's what I built, the exact commands I ran, and when you'd actually reach for each one.&lt;/p&gt;


&lt;h2&gt;
  
  
  Mint 1: Transfer Fee (Days 50–51)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mint address:&lt;/strong&gt; &lt;code&gt;ACvRnk4m9fDji76fq74n7Nzwo6tUcPyajmgi3jX9BY1Q&lt;/code&gt;&lt;br&gt;
&lt;a href="https://explorer.solana.com/address/ACvRnk4m9fDji76fq74n7Nzwo6tUcPyajmgi3jX9BY1Q?cluster=devnet" rel="noopener noreferrer"&gt;View on Solana Explorer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Extension:&lt;/strong&gt; &lt;code&gt;TransferFeeConfig&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;spl-token create-token &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--program-id&lt;/span&gt; TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--decimals&lt;/span&gt; 6 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--transfer-fee-basis-points&lt;/span&gt; 100 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--transfer-fee-maximum-fee&lt;/span&gt; 1000000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a mint where every transfer automatically withholds 1%&lt;br&gt;
(100 basis points) into the recipient's account. The recipient can't spend the withheld amount — only the withdraw authority (whoever created the mint) can sweep it out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When you'd use this:&lt;/strong&gt; Protocol treasury fees, creator royalties on&lt;br&gt;
a community token, or a skim on every transaction in a marketplace.&lt;br&gt;
The fee logic is enforced by the Token-2022 program itself. No wallet, no dApp, no smart contract can route around it.&lt;/p&gt;

&lt;p&gt;After creating the mint, I transferred 1,000 tokens to a second wallet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;spl-token transfer &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--expected-fee&lt;/span&gt; 10 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nv"&gt;$MINT&lt;/span&gt; 1000 &lt;span class="nv"&gt;$RECIPIENT&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--allow-unfunded-recipient&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;--expected-fee 10&lt;/code&gt; flag is a safety check — the transfer aborts if the calculated fee doesn't match. Out of 1,000 tokens sent, the recipient received 990. Ten tokens sat withheld in their account until I swept them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;spl-token withdraw-withheld-tokens &lt;span class="nv"&gt;$MY_TOKEN_ACCOUNT&lt;/span&gt; &lt;span class="nv"&gt;$RECIPIENT_TOKEN_ACCOUNT&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My final balance: 1,000,010 tokens. That extra 10 is the fee I collected.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mint 2: Transfer Fee + Interest (Day 52)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mint address:&lt;/strong&gt; &lt;code&gt;A2qxipYpyY4gs1BAwv45U88Uj9RuuseEwCiB3s76ZB2J&lt;/code&gt;&lt;br&gt;
&lt;a href="https://explorer.solana.com/address/A2qxipYpyY4gs1BAwv45U88Uj9RuuseEwCiB3s76ZB2J?cluster=devnet" rel="noopener noreferrer"&gt;View on Solana Explorer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Extensions:&lt;/strong&gt; &lt;code&gt;TransferFeeConfig&lt;/code&gt; + &lt;code&gt;InterestBearingConfig&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;spl-token create-token &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--program-id&lt;/span&gt; TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--decimals&lt;/span&gt; 6 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--transfer-fee-basis-points&lt;/span&gt; 100 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--transfer-fee-maximum-fee&lt;/span&gt; 1000000 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--interest-rate&lt;/span&gt; 5000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One command. Two extensions. Both baked into the same mint account.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What the interest extension actually does — and doesn't do:&lt;/strong&gt;&lt;br&gt;
This is the part I wish someone had told me upfront. The&lt;br&gt;
&lt;code&gt;InterestBearingConfig&lt;/code&gt; extension does &lt;em&gt;not&lt;/em&gt; mint new tokens over&lt;br&gt;
time. Your raw on-chain balance never changes. What changes is the &lt;em&gt;displayed&lt;/em&gt; (UI) amount — a formula applied on the fly using the stored rate and the network's clock:&lt;br&gt;
&lt;code&gt;UI Amount = raw_balance × e^(rate × elapsed_years)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It's a view, not a balance update. No transaction runs. No new tokens appear. The number you see in a wallet grows because the display formula grows — not because your account data changed.&lt;/p&gt;

&lt;p&gt;To make the effect visible quickly I used 50% APR (5,000 basis&lt;br&gt;
points). Two snapshots 30 seconds apart:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;Snapshot 1: 1,000,000.069191 tokens
Snapshot 2: 1,000,000.544703 tokens
Growth:     +0.475512 tokens in 30s
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No transaction ran between those two reads.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When you'd use this:&lt;/strong&gt; Yield-bearing stablecoins, savings-style&lt;br&gt;
tokens, or any token where you want the displayed value to grow as a function of time without actually minting supply on a schedule.&lt;/p&gt;


&lt;h2&gt;
  
  
  Mint 3: Non-Transferable / Soulbound (Day 54)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mint address:&lt;/strong&gt; &lt;code&gt;39eGRkFWbb52icCEdoaqSRtjH257KGHhhssZ2J3b2RdA&lt;/code&gt;&lt;br&gt;
&lt;a href="https://explorer.solana.com/address/39eGRkFWbb52icCEdoaqSRtjH257KGHhhssZ2J3b2RdA?cluster=devnet" rel="noopener noreferrer"&gt;View on Solana Explorer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Extension:&lt;/strong&gt; &lt;code&gt;NonTransferable&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;spl-token create-token &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--program-id&lt;/span&gt; TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--enable-non-transferable&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This mint produces tokens that cannot be sent anywhere. Once a token lands in a wallet, it stays there. The holder is the holder forever.&lt;/p&gt;

&lt;p&gt;I minted one token to myself, created a recipient wallet, then tried to transfer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;spl-token transfer &lt;span class="nv"&gt;$MINT&lt;/span&gt; 1 &lt;span class="nv"&gt;$RECIPIENT&lt;/span&gt; &lt;span class="nt"&gt;--allow-unfunded-recipient&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error 0x25: NonTransferable — token program rejected transfer
Transaction simulation failed: Error processing instruction
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That error didn't come from my code. It didn't come from a smart&lt;br&gt;
contract I wrote. It came from the Token-2022 program refusing the instruction. My balance was unchanged. The token was still with me.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When you'd use this:&lt;/strong&gt; Course completion badges, KYC verification tokens, DAO membership credentials, employee IDs. Anything where the value comes from &lt;em&gt;who holds it&lt;/em&gt;, not from being tradeable.&lt;/p&gt;

&lt;p&gt;In Web2, you'd enforce this at the application layer — a database&lt;br&gt;
constraint, an API check. Someone who talks to the database directly can bypass that. On Solana the rule is inside the program that owns the asset. There is no around.&lt;/p&gt;


&lt;h2&gt;
  
  
  What the Audit Taught Me
&lt;/h2&gt;

&lt;p&gt;On Day 53 I ran the Solana equivalent of &lt;code&gt;DESCRIBE&lt;/code&gt; against all three mints — reading every extension the protocol sees on each account:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;spl-token display &lt;span class="nv"&gt;$MINT_ADDRESS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output confirmed everything I had configured was actually there.&lt;br&gt;
But the more interesting thing was the account sizes:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mint&lt;/th&gt;
&lt;th&gt;Extensions&lt;/th&gt;
&lt;th&gt;Size&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Day 50&lt;/td&gt;
&lt;td&gt;TransferFeeConfig&lt;/td&gt;
&lt;td&gt;278 bytes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Day 52&lt;/td&gt;
&lt;td&gt;TransferFeeConfig + InterestBearingConfig&lt;/td&gt;
&lt;td&gt;334 bytes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;56 bytes more for the second extension. Those bytes cost SOL in&lt;br&gt;
rent-exempt deposits. Extensions are not free. You choose them&lt;br&gt;
deliberately at mint creation time — and you can't add them later.&lt;br&gt;
That constraint forces upfront design in a way I actually appreciate.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Surprised Me
&lt;/h2&gt;

&lt;p&gt;The thing I expected least: extensions are completely independent.&lt;br&gt;
The transfer fee operates on the raw token amount. The interest&lt;br&gt;
display formula also operates on the raw amount. They don't interfere with each other at all. I kept expecting some interaction, some edge case where they'd conflict. There isn't one. Two different TLV entries in the same byte buffer, each doing its own thing, neither knowing the other exists.&lt;/p&gt;

&lt;p&gt;The thing I'd reach for in a real product: &lt;code&gt;NonTransferable&lt;/code&gt; +&lt;br&gt;
metadata on a single mint. A credential system where the badge is&lt;br&gt;
self-describing (name, issuer, URI) and permanently bound to the&lt;br&gt;
wallet that earned it. No backend. No revocation list. Just a token with rules baked in.&lt;/p&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://solana.com/docs/tokens/extensions" rel="noopener noreferrer"&gt;Token-2022 extensions overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://solana.com/docs/tokens/extensions/transfer-fees" rel="noopener noreferrer"&gt;Transfer Fee extension docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://solana.com/docs/tokens/extensions/interest-bearing-mint" rel="noopener noreferrer"&gt;Interest-Bearing extension docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://solana.com/docs/tokens/extensions/non-transferable" rel="noopener noreferrer"&gt;Non-Transferable extension docs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;This post is part of *&lt;/em&gt;#100DaysOfSolana*&lt;em&gt;. Building on devnet every day — follow along or jump in any time.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>solana</category>
      <category>web3</category>
      <category>100daysofsolana</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Solana NFTs Without Metaplex: What I Built with Token Extensions published</title>
      <dc:creator>Lymah</dc:creator>
      <pubDate>Tue, 09 Jun 2026 16:08:47 +0000</pubDate>
      <link>https://dev.to/lymah/solana-nfts-without-metaplex-what-i-built-with-token-extensionspublished-7do</link>
      <guid>https://dev.to/lymah/solana-nfts-without-metaplex-what-i-built-with-token-extensionspublished-7do</guid>
      <description>&lt;p&gt;Before this week, I thought minting an NFT on Solana meant learning Metaplex. It turns out you can mint a full NFT — with metadata, a collection, and live mutation — using just the Token Extensions program and about 50 lines of Node.js.&lt;/p&gt;

&lt;p&gt;Here's what I actually built, what surprised me, and what I'd do differently.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Mental Model: What Is a Solana NFT?
&lt;/h2&gt;

&lt;p&gt;Strip away the marketplaces and the profile pictures and an NFT on Solana&lt;br&gt;
is just a token mint with three properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Supply = 1&lt;/strong&gt; — only one copy exists&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decimals = 0&lt;/strong&gt; — it can't be split into fractions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mint authority disabled&lt;/strong&gt; — nobody can ever create a second copy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it. The same SPL Token program that handles fungible tokens handles&lt;br&gt;
NFTs. The only difference is the configuration.&lt;/p&gt;

&lt;p&gt;With the &lt;strong&gt;Token Extensions Program&lt;/strong&gt; (Token-2022), you can go further. You attach extensions to the mint at creation time that add behavior at the protocol level. For NFTs, the relevant ones are:&lt;br&gt;
| Extension | What it does |&lt;br&gt;
|-----------|-------------|&lt;br&gt;
| &lt;strong&gt;MetadataPointer&lt;/strong&gt; | Points to the account that holds the token's metadata |&lt;br&gt;
| &lt;strong&gt;TokenMetadata&lt;/strong&gt; | Stores name, symbol, URI, and custom fields on the mint itself |&lt;br&gt;
| &lt;strong&gt;GroupPointer&lt;/strong&gt; | Marks a mint as a collection |&lt;br&gt;
| &lt;strong&gt;GroupMemberPointer&lt;/strong&gt; | Links a mint to a parent collection |&lt;/p&gt;

&lt;p&gt;No Metaplex account. No companion program. The metadata lives on the mint.&lt;/p&gt;


&lt;h2&gt;
  
  
  What I Built: Four Days, One NFT Arc
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Day 1: The bare 1-of-1
&lt;/h3&gt;

&lt;p&gt;I started with the simplest possible NFT — no metadata, no name, just the three properties above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Create a mint with 0 decimals using original SPL Token&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;createMintTx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Transaction&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;SystemProgram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createAccount&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;fromPubkey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;newAccountPubkey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;space&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lamports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;mintLamports&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;programId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;TOKEN_PROGRAM_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="nf"&gt;createInitializeMintInstruction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;               &lt;span class="c1"&gt;// decimals&lt;/span&gt;
    &lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;TOKEN_PROGRAM_ID&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// After minting 1 token, permanently disable the mint authority&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sendAndConfirmTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Transaction&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;createSetAuthorityInstruction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;AuthorityType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MintTokens&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;            &lt;span class="c1"&gt;// null = disable forever&lt;/span&gt;
    &lt;span class="p"&gt;[],&lt;/span&gt;
    &lt;span class="nx"&gt;TOKEN_PROGRAM_ID&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Opening this in Solana Explorer showed "Unknown Token" — no name, no image, just an address. That blankness was the point. It proved the NFT-ness has nothing to do with the presentation layer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Day 2: Stamping metadata with Token-2022
&lt;/h3&gt;

&lt;p&gt;The next day I rebuilt it using Token-2022 with the MetadataPointer and TokenMetadata extensions. Now the name, symbol, and URI live on the mint account itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Key instruction: write metadata directly onto the mint&lt;/span&gt;
&lt;span class="nf"&gt;createInitializeInstruction&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;programId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;           &lt;span class="c1"&gt;// metadata lives on the mint itself&lt;/span&gt;
  &lt;span class="na"&gt;updateAuthority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;mintAuthority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;First Light&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;symbol&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;LIGHT&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://gist.githubusercontent.com/.../metadata.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this transaction confirmed, the Explorer rendered the token with its name, symbol, and image fetched from the URI. It looked like a real NFT because it was one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Day 3: Wrapping it in a collection
&lt;/h3&gt;

&lt;p&gt;Collections on Token-2022 use two extension pairs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;collection mint&lt;/strong&gt; gets &lt;code&gt;GroupPointer&lt;/code&gt; + &lt;code&gt;TokenGroup&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Each &lt;strong&gt;member NFT&lt;/strong&gt; gets &lt;code&gt;GroupMemberPointer&lt;/code&gt; + &lt;code&gt;TokenGroupMember&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The member extension stores a pointer back to the collection. This is exactly a foreign key in a relational database — the collection is the parent table, and each NFT is a child row.&lt;/p&gt;

&lt;p&gt;After minting two member NFTs, the collection mint's Token Group showed &lt;code&gt;size: 2, maxSize: 3&lt;/code&gt;. Any wallet or marketplace can verify membership by reading that pointer without trusting any off-chain index.&lt;/p&gt;

&lt;h3&gt;
  
  
  Day 4: Mutating metadata live
&lt;/h3&gt;

&lt;p&gt;The metadata extension is mutable as long as you hold the update authority. This turned out to be the most interesting day.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Rename the NFT&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sendAndConfirmTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Transaction&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;createUpdateFieldInstruction&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;programId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PublicKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;NFT_MINT&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;updateAuthority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;field&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Field Notes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="c1"&gt;// Add a custom key-value pair&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;updateField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;NFT_MINT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;edition&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;field-test-1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Remove it&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sendAndConfirmTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Transaction&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;createRemoveKeyInstruction&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;programId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PublicKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;NFT_MINT&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;updateAuthority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rarity&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;idempotent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each of those is a single transaction. The on-chain name changed instantly. The image in the wallet lagged for a while — it was cached. That gap between the on-chain layer (instant) and the off-chain image layer (cached) is one of the more practical things I learned this week.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Surprising Parts
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Extensions are declared at creation time and can't be added later.&lt;/strong&gt;&lt;br&gt;
This is the Solana version of "schema decisions are forever." If you create a mint and forget to include &lt;code&gt;GroupMemberPointer&lt;/code&gt;, you can't patch it in.&lt;br&gt;
You have to mint a new token. This forces upfront design in a way that felt restrictive at first but is actually good discipline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The instruction order inside a transaction matters.&lt;/strong&gt;&lt;br&gt;
Extension initializers must run before &lt;code&gt;createInitializeMintInstruction&lt;/code&gt;. I got a cryptic &lt;code&gt;InvalidAccountData&lt;/code&gt; error the first time I got this wrong.&lt;br&gt;
Once I understood that extensions configure the account before the mint is initialized, the order made sense.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Windows doesn't have the spl-token CLI.&lt;/strong&gt;&lt;br&gt;
I did every challenge in Node.js using &lt;code&gt;@solana/web3.js&lt;/code&gt; and&lt;br&gt;
&lt;code&gt;@solana/spl-token&lt;/code&gt; directly. This was harder than using the CLI but taught me more — I had to understand the actual instructions rather than just running commands.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fungible vs NFT comparison is just numbers.&lt;/strong&gt;&lt;br&gt;
Running an audit script against my Day 30 fungible token alongside my NFTs made this concrete:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Property&lt;/th&gt;
&lt;th&gt;Fungible (Day 30)&lt;/th&gt;
&lt;th&gt;NFT (Day 44)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Supply&lt;/td&gt;
&lt;td&gt;1,000,000,000 base units&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Decimals&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mint authority&lt;/td&gt;
&lt;td&gt;Active&lt;/td&gt;
&lt;td&gt;Disabled&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Extensions&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;MetadataPointer, TokenMetadata&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Account size&lt;/td&gt;
&lt;td&gt;82 bytes&lt;/td&gt;
&lt;td&gt;469 bytes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Same program. Same instruction set. Just different configuration.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I'd Build Next
&lt;/h2&gt;

&lt;p&gt;The natural next step is exploring &lt;strong&gt;Metaplex Core&lt;/strong&gt; — the higher-level NFT standard that most production projects on Solana use. Now that I understand what Token Extensions give you natively, I can actually evaluate what Metaplex adds (royalty enforcement, collection verification, creator splits) versus what you get for free at the protocol level.&lt;/p&gt;

&lt;p&gt;I'm also curious about &lt;strong&gt;Arweave and IPFS for URI hosting&lt;/strong&gt;. Right now my NFT points at a GitHub Gist. That's fine for devnet experiments, but the whole point of an immutable on-chain pointer is that the thing it points at should also be permanent. A mutable Gist defeats that.&lt;/p&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://solana.com/docs/tokens/extensions" rel="noopener noreferrer"&gt;Token Extensions overview&lt;/a&gt; — the canonical reference&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://solana.com/docs/tokens/extensions/metadata" rel="noopener noreferrer"&gt;Metadata Pointer and Token Metadata extensions&lt;/a&gt; — what I used for on-chain metadata&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://solana.com/docs/tokens/extensions/token-group" rel="noopener noreferrer"&gt;Token Groups and Members&lt;/a&gt; — how collections work&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://explorer.solana.com/?cluster=devnet" rel="noopener noreferrer"&gt;Solana Explorer (devnet)&lt;/a&gt; — where I verified every step&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developers.metaplex.com/core" rel="noopener noreferrer"&gt;Metaplex Core&lt;/a&gt; — the production NFT standard worth knowing&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This post is part of &lt;strong&gt;#100DaysOfSolana&lt;/strong&gt;. I'm building every day on devnet&lt;br&gt;
— follow along or jump in any day.&lt;/p&gt;

</description>
      <category>solana</category>
      <category>nft</category>
      <category>webdev</category>
      <category>100daysofsolana</category>
    </item>
    <item>
      <title>Soulbound Credentials on Solana: Building Revocable Tokens with Non-Transferable + Permanent Delegate</title>
      <dc:creator>Lymah</dc:creator>
      <pubDate>Mon, 01 Jun 2026 21:25:42 +0000</pubDate>
      <link>https://dev.to/lymah/soulbound-credentials-on-solana-building-revocable-tokens-with-non-transferable-permanent-5h2a</link>
      <guid>https://dev.to/lymah/soulbound-credentials-on-solana-building-revocable-tokens-with-non-transferable-permanent-5h2a</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;I spent 7 days learning Solana token extensions. Here's what clicked, what surprised me, and the code you need to build tokens that can't be traded but can be revoked.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  The Problem (In Web2 Terms)
&lt;/h2&gt;

&lt;p&gt;Imagine you work in HR. You issue an employee a digital badge proving they're a certified security officer. Here's what you'd want:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The badge stays &lt;strong&gt;in their wallet&lt;/strong&gt; — they can't trade or sell it&lt;/li&gt;
&lt;li&gt;Only they can use it&lt;/li&gt;
&lt;li&gt;If they leave the company or fail a compliance check, you can revoke it silently without their permission&lt;/li&gt;
&lt;li&gt;The badge metadata (name, symbol, type) is &lt;strong&gt;on-chain and permanent&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You could build this with centralized databases and APIs. On Solana, it's just &lt;strong&gt;three extensions on a token mint&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Are Token Extensions?
&lt;/h2&gt;

&lt;p&gt;Solana's &lt;strong&gt;Token-2022 program&lt;/strong&gt; lets you attach additional behaviors to any mint at creation time. Think of them like middleware for tokens.&lt;br&gt;
Before extensions, every token was the same — a mint with supply and decimals, token accounts holding balances, and transfer instructions. Extensions let you add &lt;strong&gt;rules on top&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Extension&lt;/th&gt;
&lt;th&gt;What It Does&lt;/th&gt;
&lt;th&gt;Use Case&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Transfer Fee&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Charge a percentage on every transfer&lt;/td&gt;
&lt;td&gt;Protocol revenue, marketplace commissions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Non-Transferable&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Make tokens unmovable after minting&lt;/td&gt;
&lt;td&gt;Soulbound badges, credentials, memberships&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Permanent Delegate&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Let the issuer burn tokens from anyone&lt;/td&gt;
&lt;td&gt;Revocable credentials, subscriptions with expiry&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Metadata&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Store name, symbol, URI on-chain&lt;/td&gt;
&lt;td&gt;Self-describing tokens, no external API needed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Default Account State&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Freeze all new accounts by default&lt;/td&gt;
&lt;td&gt;Compliance gates, KYC verification&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The critical rule: &lt;strong&gt;extensions must be declared at mint creation&lt;/strong&gt;. You cannot add them later. This forces you to think about your token's full lifecycle before deploying — which is good design discipline.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Journey: Three Combinations That Matter
&lt;/h2&gt;

&lt;p&gt;Over the past week I built three different token types. Here's what I learned from each.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Day 34: Transfer Fees (The Marketplace Token)&lt;/strong&gt;&lt;br&gt;
A token that charges 1% on every transfer, withheld automatically and sweepable by the issuer.&lt;br&gt;
&lt;strong&gt;What clicked&lt;/strong&gt;: Fees are calculated at the protocol level — there's no fee handler to bypass. If someone transfers your token, the fee is withheld. Full stop.&lt;br&gt;
&lt;strong&gt;Day 37: Multi-Extension Token (The Compliance Token)&lt;/strong&gt;&lt;br&gt;
I combined three extensions at once: &lt;strong&gt;TransferFeeConfig + InterestBearingConfig + MetadataPointer.&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What clicked&lt;/strong&gt;: Extensions are truly independent. The interest-bearing display formula applies regardless of whether a fee is configured. The metadata doesn't affect functionality. They compose without interfering.&lt;br&gt;
&lt;strong&gt;Days 38–40: Soulbound Credentials (The Revocable Badge)&lt;/strong&gt;&lt;br&gt;
The combination that unlocked a genuinely new primitive:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;NonTransferable&lt;/strong&gt; — token can't move&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PermanentDelegate&lt;/strong&gt; — issuer can revoke without the holder's consent&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MetadataPointer&lt;/strong&gt; — credential is self-describing on-chain&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  The Code: Building a Revocable Credential
&lt;/h2&gt;

&lt;p&gt;I'm on Windows without access to the &lt;code&gt;spl-token&lt;/code&gt; CLI, so I built this entirely in Node.js using &lt;code&gt;@solana/web3.js&lt;/code&gt; and &lt;code&gt;@solana/spl-token.&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Keypair&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;SystemProgram&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Transaction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;sendAndConfirmTransaction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@solana/web3.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;ExtensionType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;createInitializeMintInstruction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;createInitializeNonTransferableMintInstruction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;createInitializePermanentDelegateInstruction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;createInitializeMetadataPointerInstruction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;getMintLen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;getAssociatedTokenAddressSync&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;createAssociatedTokenAccountInstruction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;mintTo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;createBurnInstruction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@solana/spl-token&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createInitializeInstruction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pack&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;TYPE_SIZE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;LENGTH_SIZE&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@solana/spl-token-metadata&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.devnet.solana.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;confirmed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Load your saved keypairs (never generate fresh keypairs on every run)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;authority&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;loadWallet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;~/.config/solana/id.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// issuer&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;recipient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;loadWallet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;~/recipient-wallet.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// holder&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mintKeypair&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Keypair&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;                   &lt;span class="c1"&gt;// new mint each run&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mintKeypair&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define metadata&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tokenMetadata&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Solana Dev Credential&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;symbol&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;CRED&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://example.com/credential.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;additionalMetadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Calculate space: base mint + extensions + metadata&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;metadataExtLen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;TYPE_SIZE&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;LENGTH_SIZE&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;pack&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tokenMetadata&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;extensions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="nx"&gt;ExtensionType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NonTransferable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;ExtensionType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PermanentDelegate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;ExtensionType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MetadataPointer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mintLen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getMintLen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;extensions&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mintLamports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getMinimumBalanceForRentExemption&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;mintLen&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;metadataExtLen&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Build the transaction — instruction order matters&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;createMintTx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Transaction&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="c1"&gt;// 1. Allocate the account&lt;/span&gt;
  &lt;span class="nx"&gt;SystemProgram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createAccount&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;fromPubkey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;newAccountPubkey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;space&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;mintLen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lamports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;mintLamports&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;programId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="c1"&gt;// 2. Extension initializers MUST come before createInitializeMintInstruction&lt;/span&gt;
  &lt;span class="nf"&gt;createInitializeNonTransferableMintInstruction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nf"&gt;createInitializePermanentDelegateInstruction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// issuing authority = permanent delegate&lt;/span&gt;
    &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;
  &lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nf"&gt;createInitializeMetadataPointerInstruction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;
  &lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="c1"&gt;// 3. Initialize the mint itself (0 decimals — credentials are whole units)&lt;/span&gt;
  &lt;span class="nf"&gt;createInitializeMintInstruction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;
  &lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="c1"&gt;// 4. Write metadata on-chain&lt;/span&gt;
  &lt;span class="nf"&gt;createInitializeInstruction&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;programId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;updateAuthority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;mintAuthority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;tokenMetadata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;symbol&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;tokenMetadata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;symbol&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;tokenMetadata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sendAndConfirmTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;createMintTx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mintKeypair&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;✅ Mint created:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBase58&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="c1"&gt;// Create recipient's token account (authority pays)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;recipientATA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getAssociatedTokenAddressSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;recipient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;createATATx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Transaction&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;createAssociatedTokenAccountInstruction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;recipientATA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;recipient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sendAndConfirmTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;createATATx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="c1"&gt;// Mint 1 credential to the recipient&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;mintTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;recipientATA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nc"&gt;BigInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;✅ Credential issued to recipient&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// === TRANSFER ATTEMPT — will fail ===&lt;/span&gt;
&lt;span class="c1"&gt;// (Try this yourself — the NonTransferable extension blocks it at simulation)&lt;/span&gt;

&lt;span class="c1"&gt;// === REVOCATION — authority burns without holder's consent ===&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;revokeTx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Transaction&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;createBurnInstruction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;recipientATA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;mint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// permanent delegate signs — NOT the holder&lt;/span&gt;
    &lt;span class="nc"&gt;BigInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;[],&lt;/span&gt;
    &lt;span class="nx"&gt;TOKEN_2022_PROGRAM_ID&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sendAndConfirmTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;revokeTx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;authority&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;✅ Credential revoked — recipient balance: 0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  What Surprised Me
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Silent revocation is real&lt;/strong&gt;. I expected revoking to require the holder's signature. It doesn't. The permanent delegate burns the token without any interaction from the holder. For compliance scenarios, that's exactly what you want — but it's worth being deliberate about who you hand this power to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transfer is blocked at simulation, before the chain&lt;/strong&gt;. When I tried to transfer a NonTransferable token, the RPC rejected the transaction before it was even submitted. No gas spent, no on-chain footprint. The rejection is that clean.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Instruction order is unforgiving&lt;/strong&gt;. Extension initializers must run before &lt;code&gt;createInitializeMintInstruction&lt;/code&gt; in the same transaction. Put them in the wrong order and you get a cryptic error. Once I understood that extensions configure the account before the mint is initialized, the order made sense.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Confused Me
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Token accounts vs. mints&lt;/strong&gt;. For the first few days I kept conflating these. The &lt;strong&gt;mint&lt;/strong&gt; holds supply, decimals, authorities, and extensions. A &lt;strong&gt;token account&lt;/strong&gt; (ATA) is where a holder's balance lives. Extensions live on the mint. Token accounts just hold tokens and follow the mint's rules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why so many instructions?&lt;/strong&gt; Creating a mint with three extensions means six instructions in one transaction. The reason is modularity — you only pay for what you use. A basic mint is one instruction. A complex mint is six. Cost scales with your needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Clicked
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Extensions are middleware, not token types&lt;/strong&gt;. I kept thinking of NonTransferable tokens as a different kind of token. They're not. It's the same token with a rule bolted on. Transfer fee is a rule. Permanent delegate is a rule. Rules compose.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;This unlocks genuinely new primitives&lt;/strong&gt;. Before Token-2022 extensions, soulbound + revocable in a single token was not possible on Solana without a custom program. Now it's a 50-line script. That matters.
&lt;/h2&gt;

&lt;h2&gt;
  
  
  The Real Gotchas
&lt;/h2&gt;

&lt;p&gt;Save your keypairs. Generate once, save to JSON, load on every run. Generating fresh keypairs every time means your authority has no SOL on the next run.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Save&lt;/span&gt;
&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;authority.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;kp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;secretKey&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;

&lt;span class="c1"&gt;// Load&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;kp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Keypair&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromSecretKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nb"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;authority.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;utf8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Always pass&lt;/strong&gt; &lt;code&gt;TOKEN_2022_PROGRAM_ID&lt;/code&gt; &lt;strong&gt;when working with Token-2022 mints&lt;/strong&gt;. The default program ID in most helper functions points to the original SPL Token program. Pass the wrong one and your transactions fail with confusing errors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Base units, not whole tokens&lt;/strong&gt;. Every numeric parameter is in base units. With 0 decimals this is fine — 1 base unit = 1 token. With 9 decimals, &lt;code&gt;BigInt(1)&lt;/code&gt; = 0.000000001 tokens. Always scale by &lt;code&gt;10 ** decimals&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  How This Compares to Web2
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Web2&lt;/th&gt;
&lt;th&gt;Solana Extensions&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Issue a credential&lt;/td&gt;
&lt;td&gt;API call, DB entry&lt;/td&gt;
&lt;td&gt;Mint a token with extensions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Holder keeps it forever&lt;/td&gt;
&lt;td&gt;Require them to log in to see it&lt;/td&gt;
&lt;td&gt;Non-Transferable: it just lives in their wallet&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Revoke silently&lt;/td&gt;
&lt;td&gt;Flip a flag in your DB, holder doesn't know&lt;/td&gt;
&lt;td&gt;Permanent Delegate: authority burns it without consent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Verify credential&lt;/td&gt;
&lt;td&gt;Call your API&lt;/td&gt;
&lt;td&gt;Query the chain for the token balance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cost&lt;/td&gt;
&lt;td&gt;Your servers, your infrastructure&lt;/td&gt;
&lt;td&gt;Minimal (rent-exempt account on Solana)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The shift: &lt;strong&gt;you don't control the infrastructure&lt;/strong&gt;. The token is self-custody. The rules are on-chain. The program enforces them, not your API.&lt;/p&gt;




&lt;h2&gt;
  
  
  Going Deeper
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://solana.com/docs/tokens/extensions" rel="noopener noreferrer"&gt;official Token Extensions documentation&lt;/a&gt; covers every extension with parameters, use cases, and CLI examples. If you're following the &lt;strong&gt;100 Days of Solana&lt;/strong&gt; challenge, the extension challenges build on each other across several days — start with a basic mint, add metadata, add transfer fees, then combine everything.&lt;br&gt;
Extensions I haven't tried yet that look interesting:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Interest-bearing&lt;/strong&gt; — display a time-adjusted balance using continuous compounding, no new tokens minted&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Confidential transfers&lt;/strong&gt; — encrypted token amounts on a public chain&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Oracle-driven freezes&lt;/strong&gt; — freeze accounts based on external data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The pattern is clear: token behavior is becoming a set of composable, declared rules. That's what programmable money looks like.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Built on Solana devnet. All code written in Node.js on Windows — no CLI available, every challenge solved programmatically using &lt;code&gt;@solana/web3.js&lt;/code&gt; and &lt;code&gt;@solana/spl-token.&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>100daysofsolana</category>
      <category>solana</category>
      <category>web3</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Transfer Fees, Metadata, and Soulbound Tokens: A Tour of Solana Token Extensions</title>
      <dc:creator>Lymah</dc:creator>
      <pubDate>Sun, 24 May 2026 23:02:29 +0000</pubDate>
      <link>https://dev.to/lymah/transfer-fees-metadata-and-soulbound-tokens-a-tour-of-solana-token-extensions-la1</link>
      <guid>https://dev.to/lymah/transfer-fees-metadata-and-soulbound-tokens-a-tour-of-solana-token-extensions-la1</guid>
      <description>&lt;p&gt;I spent the past week building tokens on Solana. Not wrapping existing ones, not swapping — actually creating token mints from scratch, attaching economic rules to them at the protocol level, and watching a blockchain reject a transaction I told it to make. This post walks through what I built, what surprised me, and why the Token Extensions Program changes how I think about on-chain rules.&lt;/p&gt;




&lt;h2&gt;
  
  
  Where I Started
&lt;/h2&gt;

&lt;p&gt;My background is Web2. I know how platforms build internal currencies — a database table for balances, API endpoints for transfers, middleware to collect fees, application logic to enforce rules like "this badge can't be sold." It works, but the rules live in code that can be changed, bypassed, or taken offline.&lt;/p&gt;

&lt;p&gt;My starting question going into this was simple: what does Solana actually give you that a well-designed backend doesn't? By the end of the week, I had a concrete answer.&lt;/p&gt;




&lt;h2&gt;
  
  
  1: Your First Mint (It's Just an Account)
&lt;/h2&gt;

&lt;p&gt;The first thing that reframes everything is understanding that a token on Solana is not a smart contract. It's an account — specifically a &lt;strong&gt;Mint account&lt;/strong&gt; — that stores three pieces of state: total supply, decimal precision, and the address that's allowed to create more tokens (the mint authority).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;spl-token create-token
spl-token create-account YOUR_MINT_ADDRESS
spl-token mint YOUR_MINT_ADDRESS 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What surprised me: you can't receive tokens directly into your wallet. Every wallet needs a dedicated &lt;strong&gt;token account&lt;/strong&gt; for each token type it holds. Think of your wallet as a filing cabinet — each token account is a labeled folder inside it. It felt awkward at first, but it's how Solana keeps account state fast and cheap to look up.&lt;/p&gt;

&lt;p&gt;The Mint account is the source of truth. The token account is where your specific balance lives. One program, the &lt;strong&gt;SPL Token Program&lt;/strong&gt;, manages both.&lt;/p&gt;




&lt;h2&gt;
  
  
  2: Metadata — Giving Your Token an Identity
&lt;/h2&gt;

&lt;p&gt;A freshly minted token has no name, no symbol, nothing. In a block explorer it shows up as "Unknown Token." That's where the &lt;strong&gt;Token Extensions Program&lt;/strong&gt; (Token-2022) comes in.&lt;/p&gt;

&lt;p&gt;Instead of storing metadata in a separate account (the old Metaplex approach), Token-2022 lets you attach metadata directly to the mint account itself using the metadata extension.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;spl-token create-token &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--program-id&lt;/span&gt; TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--enable-metadata&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--decimals&lt;/span&gt; 6

spl-token initialize-metadata YOUR_MINT &lt;span class="s2"&gt;"100DaysCoin"&lt;/span&gt; &lt;span class="s2"&gt;"HUNDO"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s2"&gt;"https://your-metadata-uri.json"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result: a single mint account that holds the token's supply, decimal config, mint authority, &lt;em&gt;and&lt;/em&gt; its name and symbol. Fewer accounts, fewer transactions, lower cost. After running this I could see &lt;code&gt;100DaysCoin (HUNDO)&lt;/code&gt; show up properly in the Solana Explorer on devnet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key insight:&lt;/strong&gt; The URI in the metadata points to a JSON file with extended details (description, image, attributes). It's the same pattern as NFT metadata — one on-chain pointer to off-chain details.&lt;/p&gt;




&lt;h2&gt;
  
  
  3: Transfer Fees — Economics Without Middleware
&lt;/h2&gt;

&lt;p&gt;This is where things got genuinely interesting. In Web2, collecting a percentage of every transaction means building middleware: intercept the transfer, calculate the fee, split the payment, handle edge cases. And it can be bypassed if someone finds a way around your API.&lt;/p&gt;

&lt;p&gt;Token-2022 has a &lt;strong&gt;transfer fee extension&lt;/strong&gt; that enforces collection at the program level. When you configure it on a mint, every transfer of that token automatically withholds a percentage in the recipient's account — locked there until the withdraw authority (you) sweeps it out.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;spl-token create-token &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--program-id&lt;/span&gt; TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--transfer-fee-basis-points&lt;/span&gt; 200 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--transfer-fee-maximum-fee&lt;/span&gt; 5000000000000 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--decimals&lt;/span&gt; 9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I transferred 100 tokens at a 2% fee. The recipient received 98. Two tokens were withheld in their account, untouchable by them. Then I ran the withdraw:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;spl-token withdraw-withheld-tokens YOUR_TOKEN_ACCOUNT RECIPIENT_TOKEN_ACCOUNT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Final balance: 902. The 2 tokens came home.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What tripped me up:&lt;/strong&gt; The &lt;code&gt;--transfer-fee-maximum-fee&lt;/code&gt; parameter is in &lt;em&gt;base units&lt;/em&gt;, not whole tokens. With 9 decimals, &lt;code&gt;5000&lt;/code&gt; base units = &lt;code&gt;0.000005&lt;/code&gt; tokens — basically nothing. My first two runs had the fee capped at a fraction of a token because I forgot to scale it. The fix: multiply by &lt;code&gt;10 ** decimals&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MAX_FEE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BigInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="nx"&gt;DECIMALS&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 5000 whole tokens as cap&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the kind of thing that only clicks after you see the wrong number in your output.&lt;/p&gt;




&lt;h2&gt;
  
  
  4: The Full Lifecycle in One Run
&lt;/h2&gt;

&lt;p&gt;Day 4 was a consolidation challenge: reproduce the entire workflow — metadata + transfer fees — from a blank terminal without notes. I built a single Node.js script that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Created a Token-2022 mint with both metadata and transfer fee extensions&lt;/li&gt;
&lt;li&gt;Minted 1000 tokens&lt;/li&gt;
&lt;li&gt;Transferred 100 to a second wallet (98 received, 2 withheld)&lt;/li&gt;
&lt;li&gt;Harvested and withdrew the fees&lt;/li&gt;
&lt;li&gt;Printed the full token config as a summary
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;```Final output:&lt;/p&gt;

&lt;p&gt;Primary wallet:  902 tokens&lt;br&gt;
Second wallet:    98 tokens&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Fees collected:    2 tokens

Running it clean, without errors, in one go, felt like the proof that the concepts had actually landed.

---

## Day 5: Non-Transferable Tokens — Soulbound on the Protocol

The last experiment was the most conceptually interesting. Solana's Token-2022 has a **non-transferable extension** that permanently prevents any token from that mint from moving between wallets. Not "our API won't let you" — the transaction is rejected by the token program before it even hits the chain.



```bash
spl-token create-token \
  --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb \
  --enable-non-transferable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I minted 10 tokens, tried to transfer 5 to a second wallet, and got this:&lt;/p&gt;

&lt;p&gt;✗ TRANSFER REJECTED (This is correct!)&lt;br&gt;
Error: Transaction simulation failed: Error processing instruction&lt;br&gt;
The Non-Transferable extension blocks ALL transfers at the protocol level.&lt;/p&gt;

&lt;p&gt;Then I burned 3 tokens — and that worked fine. Balance dropped from 10 to 7.&lt;/p&gt;

&lt;p&gt;That distinction matters: &lt;strong&gt;non-transferable doesn't mean non-destructible&lt;/strong&gt;. The holder can burn their own tokens. They just can't send them to anyone else. This is exactly the behavior you'd want for things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Course completion certificates&lt;/li&gt;
&lt;li&gt;KYC verification tokens&lt;/li&gt;
&lt;li&gt;DAO membership credentials&lt;/li&gt;
&lt;li&gt;Event participation proofs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Web2, preventing credential trading means application-layer rules. Here, the restriction is part of the asset itself. No backend change, no API update, no workaround possible.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I'd Tell Myself at the Start
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Read the error messages carefully.&lt;/strong&gt; Solana program errors are specific. "NonTransferable" in an error isn't noise — it's the program telling you exactly which extension blocked you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Base units will get you.&lt;/strong&gt; Every numeric parameter involving token amounts is in base units. Always multiply by &lt;code&gt;10 ** decimals&lt;/code&gt; before passing values into instructions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Extensions are set at creation time.&lt;/strong&gt; You can't add a transfer fee to an existing mint. Design your token before you deploy it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Token-2022 is the right default now.&lt;/strong&gt; The original SPL Token Program is simpler, but Token-2022 is a strict superset. Unless you have a specific reason to use the old program, start with Token-2022.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Next
&lt;/h2&gt;

&lt;p&gt;I'm continuing through the 100 Days of Solana challenge. Next up: diving into compressed NFTs and Solana's state compression model. If you're following along or building something similar, drop a comment — I'd like to see what you're working on.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Built on Solana devnet. All code written in Node.js using &lt;code&gt;@solana/web3.js&lt;/code&gt; and &lt;code&gt;@solana/spl-token&lt;/code&gt;. Windows environment — no CLI available, so every challenge was solved programmatically.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>100daysofsolana</category>
      <category>web3</category>
      <category>blockchain</category>
      <category>solana</category>
    </item>
    <item>
      <title>Solana's System Program: Understanding the Kernel</title>
      <dc:creator>Lymah</dc:creator>
      <pubDate>Fri, 22 May 2026 06:08:17 +0000</pubDate>
      <link>https://dev.to/lymah/solanas-system-program-understanding-the-kernel-19il</link>
      <guid>https://dev.to/lymah/solanas-system-program-understanding-the-kernel-19il</guid>
      <description>&lt;h2&gt;
  
  
  The Question That Started It All
&lt;/h2&gt;

&lt;p&gt;Three posts in, I kept running into the same address:&lt;br&gt;
&lt;code&gt;11111111111111111111111111111111&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It showed up as the owner of every wallet I queried.&lt;br&gt;
It appeared in every transaction I decoded in&lt;br&gt;
&lt;a href="https://dev.to/lymah/the-solana-account-model-explained-everything-is-an-account-3g48"&gt;Post 3&lt;/a&gt;.&lt;br&gt;
My explorer from &lt;a href="https://dev.to/lymah/building-a-solana-account-explorer-query-on-chain-data-like-a-database-293d"&gt;Post 2&lt;/a&gt;&lt;br&gt;
labeled it "System Program" but I didn't really&lt;br&gt;
understand what that meant.&lt;/p&gt;

&lt;p&gt;Why can't I create an account myself? Why does the&lt;br&gt;
System Program have to do it? Why does every wallet&lt;br&gt;
on Solana belong to it?&lt;/p&gt;

&lt;p&gt;The answer reveals Solana's elegance: &lt;strong&gt;The System&lt;br&gt;
Program is Solana's kernel.&lt;/strong&gt; Like a Unix kernel&lt;br&gt;
manages processes and permissions, the System Program&lt;br&gt;
manages accounts and state creation. Understanding it&lt;br&gt;
means understanding why Solana works the way it does.&lt;/p&gt;


&lt;h2&gt;
  
  
  What is the System Program?
&lt;/h2&gt;

&lt;p&gt;Address: &lt;code&gt;11111111111111111111111111111111&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It's an account like any other:&lt;/p&gt;

&lt;p&gt;Owner:      NativeLoader&lt;br&gt;
Executable: true&lt;br&gt;
Data:       "system_program" (14 bytes of ASCII)&lt;br&gt;
Balance:    1 lamport (rent-exempt minimum)&lt;/p&gt;

&lt;p&gt;But it's special. It's built into Solana's validator&lt;br&gt;
runtime. When you send a transaction, the System&lt;br&gt;
Program enforces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Who can transfer SOL&lt;/li&gt;
&lt;li&gt;Who can create accounts&lt;/li&gt;
&lt;li&gt;How much lamports accounts must hold&lt;/li&gt;
&lt;li&gt;Account closure rules&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run this yourself and see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;solana account 11111111111111111111111111111111
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbpciyeqen2r24hcucw34.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbpciyeqen2r24hcucw34.png" alt="System Program account output showing NativeLoader owner, executable true, 14 bytes of data" width="800" height="223"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The System Program — owned by NativeLoader, built&lt;br&gt;
into the validator runtime itself.&lt;/em&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Core Insight: Programs Own Accounts, Not People
&lt;/h2&gt;

&lt;p&gt;Here's what breaks beginner brains:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your wallet is NOT owned by you. It's owned by the&lt;br&gt;
System Program.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your Wallet&lt;br&gt;
├── Owner: 11111111111111111111111111111111 (System Program)&lt;br&gt;
├── Executable: false&lt;br&gt;
├── Data: (empty)&lt;br&gt;
└── Lamports: 5000000000 (your SOL)&lt;br&gt;
Run this to see it yourself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;solana account &amp;lt;your-wallet-address&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdngo76e8mganyq6x0smd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdngo76e8mganyq6x0smd.png" alt="Wallet account showing System Program as owner, 0 bytes data, lamports balance" width="765" height="191"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Your wallet — owned by the System Program, not by&lt;br&gt;
you. Your keypair is the authorization mechanism,&lt;br&gt;
not the owner.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;But you can spend from it because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your keypair can sign for this account&lt;/li&gt;
&lt;li&gt;The System Program's rules say: "Only an account
owner or authorized keypair can transfer from
that account"&lt;/li&gt;
&lt;li&gt;Since your keypair authorized the transfer, the
System Program allows it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You don't own your account. You &lt;em&gt;authorize&lt;/em&gt;&lt;br&gt;
transactions on it. The System Program enforces&lt;br&gt;
your authorization.&lt;/p&gt;

&lt;p&gt;This is the security model: &lt;strong&gt;permission enforcement&lt;br&gt;
is separate from asset ownership.&lt;/strong&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  The System Program's Four Main Instructions
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. CreateAccount
&lt;/h3&gt;

&lt;p&gt;Creates a new account owned by you or another program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// What it does:&lt;/span&gt;
&lt;span class="c1"&gt;// 1. Allocate &amp;lt;space&amp;gt; bytes for data&lt;/span&gt;
&lt;span class="c1"&gt;// 2. Set owner to &amp;lt;owner&amp;gt; (usually your program)&lt;/span&gt;
&lt;span class="c1"&gt;// 3. Charge enough lamports to cover rent&lt;/span&gt;
&lt;span class="c1"&gt;// 4. Fund from payer's account&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Cost:&lt;/strong&gt; ~2,400 lamports for a basic account +&lt;br&gt;
space × 0.00348 lamports/byte&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Transfer
&lt;/h3&gt;

&lt;p&gt;Move SOL from one account to another.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// What it does:&lt;/span&gt;
&lt;span class="c1"&gt;// 1. Decrease sender's lamports by amount&lt;/span&gt;
&lt;span class="c1"&gt;// 2. Increase recipient's lamports by amount&lt;/span&gt;
&lt;span class="c1"&gt;// 3. Verify sender's keypair signature&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No fee beyond the network fee. The System Program&lt;br&gt;
allows SOL transfer to any account.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Allocate
&lt;/h3&gt;

&lt;p&gt;Increase an account's data space after creation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// What it does:&lt;/span&gt;
&lt;span class="c1"&gt;// 1. Expand data buffer&lt;/span&gt;
&lt;span class="c1"&gt;// 2. Charge additional lamports for rent&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Assign
&lt;/h3&gt;

&lt;p&gt;Change an account's owner.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// What it does:&lt;/span&gt;
&lt;span class="c1"&gt;// 1. Set owner to &amp;lt;new-owner&amp;gt;&lt;/span&gt;
&lt;span class="c1"&gt;// 2. Only works if current owner is System Program&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Example: The Lifecycle of Creating an Account
&lt;/h2&gt;

&lt;p&gt;When you create a token, the Token Program does this:&lt;br&gt;
User sends transaction:&lt;br&gt;
│&lt;br&gt;
├─&amp;gt; System Program.CreateAccount(...)&lt;br&gt;
│   ├─ Payer: Your wallet&lt;br&gt;
│   ├─ New Account: Token mint address&lt;br&gt;
│   ├─ Owner: Token Program&lt;br&gt;
│   └─ Space: 82 bytes&lt;br&gt;
│&lt;br&gt;
└─&amp;gt; Token Program.InitializeMint(...)&lt;br&gt;
├─ Reads the new account&lt;br&gt;
├─ Writes mint data&lt;br&gt;
└─ Returns success&lt;br&gt;
Result:&lt;br&gt;
Token Mint Account&lt;br&gt;
├── Owner: TokenkegQfe... (Token Program)&lt;br&gt;
├── Executable: false&lt;br&gt;
├── Data: (82 bytes with supply, decimals, authorities)&lt;br&gt;
└── Lamports: (rent-exempt amount)&lt;br&gt;
Notice the two-step pattern:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;System Program creates the container&lt;/strong&gt; — allocates
space, funds rent&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Token Program initializes the data&lt;/strong&gt; — writes the
mint info&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This separation is the genius: the System Program&lt;br&gt;
handles account &lt;em&gt;creation&lt;/em&gt;, programs handle&lt;br&gt;
&lt;em&gt;initialization&lt;/em&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  Rent: The System Program's Economic Rule
&lt;/h2&gt;

&lt;p&gt;The System Program enforces rent-exemption economics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You must hold:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;(account_data_size + 128) × 0.00348 lamports/byte&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Example: 1 KB account&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dataSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rentPerByte&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.00348&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// lamports&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;requiredLamports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dataSize&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;rentPerByte&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;requiredSOL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;requiredLamports&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;e9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Required: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;requiredSOL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; SOL`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check it yourself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;solana rent 1000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjug9mc2yhzchzo5yt8u9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjug9mc2yhzchzo5yt8u9.png" alt="Terminal output of solana rent 1000 showing required lamports and SOL" width="780" height="219"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The exact SOL required to rent-exempt a 1KB&lt;br&gt;
account. The System Program enforces this minimum&lt;br&gt;
at account creation.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: Only 0.000000004 SOL for 1KB — rent-exemption &lt;br&gt;
is cheap for small accounts. Scale this up to &lt;br&gt;
10MB and it becomes meaningful.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note on rent deprecation:&lt;/strong&gt; Solana deprecated&lt;br&gt;
ongoing rent collection, but the rent-exemption&lt;br&gt;
minimum is still enforced when accounts are created.&lt;br&gt;
You must fund new accounts above this threshold or&lt;br&gt;
the transaction fails.&lt;/p&gt;


&lt;h2&gt;
  
  
  Seeing It Through the Explorer
&lt;/h2&gt;

&lt;p&gt;If you built the account explorer from&lt;br&gt;
&lt;a href="https://dev.to/lymah/building-a-solana-account-explorer-query-on-chain-data-like-a-database-293d"&gt;Post 2&lt;/a&gt;,&lt;br&gt;
run it against the System Program now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node explorer.mjs 11111111111111111111111111111111
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwk2cjx0yir9yn44de4jj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwk2cjx0yir9yn44de4jj.png" alt="Explorer output for System Program showing NativeLoader, executable true, 14 bytes, 1 lamport balance" width="766" height="470"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The same explorer from Post 2 — but now you know&lt;br&gt;
exactly what you're looking at. NativeLoader means&lt;br&gt;
this program is baked into the validator, not deployed&lt;br&gt;
like other programs.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The output tells the whole story in five fields.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why This Design?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Consistency
&lt;/h3&gt;

&lt;p&gt;Every program uses the same account model. Every&lt;br&gt;
account creation uses the System Program. The&lt;br&gt;
protocol scales because you don't write custom&lt;br&gt;
account-creation logic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Security
&lt;/h3&gt;

&lt;p&gt;The System Program is battle-tested and immutable.&lt;br&gt;
Bugs there would be catastrophic. By centralizing&lt;br&gt;
account logic, Solana minimizes the surface area&lt;br&gt;
for vulnerabilities.&lt;/p&gt;

&lt;h3&gt;
  
  
  Economics
&lt;/h3&gt;

&lt;p&gt;Rent exemption is managed uniformly. Everyone follows&lt;br&gt;
the same rules: hold enough lamports and your account&lt;br&gt;
lives forever.&lt;/p&gt;

&lt;h3&gt;
  
  
  Auditability
&lt;/h3&gt;

&lt;p&gt;Want to know who owns an account? Read the &lt;code&gt;owner&lt;/code&gt;&lt;br&gt;
field. Solana's permission model is transparent and&lt;br&gt;
on-chain.&lt;/p&gt;




&lt;h2&gt;
  
  
  System Program vs. Ethereum
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Ethereum:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Anyone can create accounts implicitly&lt;/li&gt;
&lt;li&gt;Storage rent is implicit through gas fees&lt;/li&gt;
&lt;li&gt;Account ownership is straightforward&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Solana:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;System Program explicitly creates all accounts&lt;/li&gt;
&lt;li&gt;Rent-exemption is explicit — you must hold a
minimum balance&lt;/li&gt;
&lt;li&gt;Account ownership is decoupled from transaction
authorization — owner vs. signer are different things&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Solana's model is more explicit. You see the kernel.&lt;br&gt;
You can audit it. That explicitness is a feature,&lt;br&gt;
not a bug.&lt;/p&gt;




&lt;h2&gt;
  
  
  Debugging: Common System Program Errors
&lt;/h2&gt;

&lt;h3&gt;
  
  
  "Account does not have enough lamports."
&lt;/h3&gt;

&lt;p&gt;❌ You tried to create an account without funding&lt;br&gt;
it enough&lt;br&gt;
✅ Calculate the rent-exempt amount and include&lt;br&gt;
extra lamports&lt;/p&gt;

&lt;h3&gt;
  
  
  "Account is not owned by the System Program"
&lt;/h3&gt;

&lt;p&gt;❌ You tried to Assign an account owned by a&lt;br&gt;
different program&lt;br&gt;
✅ Only the System Program can Assign accounts&lt;/p&gt;

&lt;h3&gt;
  
  
  "Cannot allocate more space"
&lt;/h3&gt;

&lt;p&gt;❌ Account is owned by something other than the&lt;br&gt;
System Program&lt;br&gt;
✅ Only the System Program allows re-allocation&lt;/p&gt;




&lt;h2&gt;
  
  
  What to Do Next
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Inspect the System Program&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   solana account 11111111111111111111111111111111
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Check your own wallet's owner&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   solana account &amp;lt;your-address&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Owner will always be &lt;code&gt;11111...&lt;/code&gt; for a standard wallet.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Check rent for different sizes&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   solana rent 1000    &lt;span class="c"&gt;# 1 KB&lt;/span&gt;
   solana rent 10000   &lt;span class="c"&gt;# 10 KB&lt;/span&gt;
   solana rent 100000  &lt;span class="c"&gt;# 100 KB&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Watch how the required SOL scales with data size.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Read the System Program source&lt;/strong&gt;
The code is public. Reading it shows you the exact
validation rules the entire network runs on.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Wrapping Up Epoch 1
&lt;/h2&gt;

&lt;p&gt;This is the fourth and final post in my Epoch 1&lt;br&gt;
Writing Challenge series. What started with&lt;br&gt;
"everything is an account" ends here — with the one&lt;br&gt;
program that makes the whole account model work.&lt;/p&gt;

&lt;p&gt;If you've followed along from Post 1, you now have&lt;br&gt;
a complete mental model:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Post 1&lt;/strong&gt; — What accounts are and why they all
share five fields&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Post 2&lt;/strong&gt; — How to query any account and read
those fields directly&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Post 3&lt;/strong&gt; — How to decode the raw binary data
sitting in those fields&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Post 4&lt;/strong&gt; — The System Program that creates,
owns, and enforces rules on all of it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's Solana's foundation. Everything else — DeFi,&lt;br&gt;
NFTs, DAOs, gaming — is built on top of this.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Series: The Account Model Foundation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Part 1: &lt;a href="https://dev.to/lymah/the-solana-account-model-explained-everything-is-an-account-3g48"&gt;The Account Model Explained&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Part 2: &lt;a href="https://dev.to/lymah/building-a-solana-account-explorer-query-on-chain-data-like-a-database-293d"&gt;Building an Account Explorer&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Part 3: &lt;a href="https://dev.to/lymah/decoding-solana-account-data-three-methods-compared-4356"&gt;Decoding Account Data&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Part 4: Solana's System Program — Understanding
the Kernel &lt;em&gt;(this post)&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Have questions about the System Program? Ask in&lt;br&gt;
the comments — I'll cover advanced patterns like&lt;br&gt;
PDAs (Program Derived Addresses) in a future post.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Part of the &lt;a href="https://www.mlh.com/events/100-days-of-solana/challenges" rel="noopener noreferrer"&gt;100 Days of Solana&lt;/a&gt; Epoch 1 Writing Challenge.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>100daysofsolana</category>
      <category>writing</category>
      <category>tutorial</category>
      <category>web3</category>
    </item>
    <item>
      <title>Decoding Solana Account Data: Three Methods Compared</title>
      <dc:creator>Lymah</dc:creator>
      <pubDate>Wed, 20 May 2026 17:09:25 +0000</pubDate>
      <link>https://dev.to/lymah/decoding-solana-account-data-three-methods-compared-4356</link>
      <guid>https://dev.to/lymah/decoding-solana-account-data-three-methods-compared-4356</guid>
      <description>&lt;h2&gt;
  
  
  From Hex to Human-Readable
&lt;/h2&gt;

&lt;p&gt;At the end of &lt;a href="https://dev.to/lymah/building-a-solana-account-explorer-query-on-chain-data-like-a-database-293d"&gt;Post 2&lt;/a&gt;, my account explorer was printing this for the Token Program:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Data:
Size: 48 bytes
First 48 bytes (hex):
7436346a506...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I could see the data existed. I had no idea what it meant.&lt;/p&gt;

&lt;p&gt;That wall of hex bytes is actually structured information — token supply, decimals, mint authority. It's just encoded in binary. This post is about the three ways I learned to decode it, what each method taught me, and when to use which.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;You've got an account. You can fetch it. But the &lt;code&gt;data&lt;/code&gt; field is a binary blob:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;data:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;39&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;241&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;144&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;177&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;211&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;175&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;152&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;184&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;206&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;113&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;76&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;68&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How do you turn this into meaningful information?&lt;/p&gt;

&lt;p&gt;This is where decoding comes in. And it turns out, there are three different ways to do it in Solana. Each has tradeoffs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmikw5kxps6yuj31zmc3l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmikw5kxps6yuj31zmc3l.png" alt="Methods Fetching preparation" width="800" height="720"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Background: Account Data is Binary Borsh
&lt;/h2&gt;

&lt;p&gt;SPL (Solana Program Library) accounts use &lt;strong&gt;Borsh&lt;/strong&gt;, a binary serialization format. It's deterministic, language-independent, and compact.&lt;/p&gt;

&lt;p&gt;For example, a token mint account is 82 bytes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Bytes 0-3:       Mint discriminator
Bytes 4-35:      Mint authority (32-byte public key)
Bytes 36-43:     Total supply (u64 = 8 bytes, little-endian)
Byte 44:         Number of decimals (u8)
Bytes 45-76:     Freeze authority (32-byte public key)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Raw bytes look like nonsense. Decoding means:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reading bytes at specific offsets&lt;/li&gt;
&lt;li&gt;Interpreting them as specific types&lt;/li&gt;
&lt;li&gt;Converting little-endian → numbers&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We need a reliable way to do this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 1: Using a Codec Library
&lt;/h2&gt;

&lt;p&gt;The cleanest approach: use &lt;code&gt;@solana-program/token&lt;/code&gt; with its built-in decoders.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; @solana-program/token
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getMintDecoder&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@solana-program/token&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;base58Decoder&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@solana/codecs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;decodeWithCodec&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.mainnet-beta.solana.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Fetch the token mint&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;WRAPPED_SOL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;So11111111111111111111111111111111111111112&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;accountInfo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAccountInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PublicKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;WRAPPED_SOL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Decode using the official codec&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mintDecoder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getMintDecoder&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;decodedMint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;mintDecoder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;accountInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Method 1: Codec&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Supply:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;decodedMint&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;supply&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Decimals:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;decodedMint&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;decimals&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mint Authority:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;decodedMint&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mintAuthority&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Freeze Authority:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;decodedMint&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;freezeAuthority&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh1rbvlcghhughv0eyhum.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh1rbvlcghhughv0eyhum.png" alt="Method 1: Code Library" width="800" height="722"&gt;&lt;/a&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsg25b53rf50yygq0fnbw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsg25b53rf50yygq0fnbw.png" alt="The rest of method 1" width="722" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Type-safe&lt;/li&gt;
&lt;li&gt;✅ Official/audited&lt;/li&gt;
&lt;li&gt;✅ Handles complex types automatically&lt;/li&gt;
&lt;li&gt;✅ No manual offset calculations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❌ Only works for SPL types&lt;/li&gt;
&lt;li&gt;❌ External dependency&lt;/li&gt;
&lt;li&gt;❌ Black box — you don't see the binary&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Method 2: Manual Byte-Level Parsing
&lt;/h2&gt;

&lt;p&gt;Read raw bytes and extract fields yourself using &lt;code&gt;DataView&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;decodeManually&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;view&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DataView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Bytes 0-3: Skip discriminator&lt;/span&gt;

  &lt;span class="c1"&gt;// Bytes 4-35: Mint authority (public key = 32 bytes, stored as base58)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mintAuthBytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;36&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Bytes 36-43: Supply (u64, little-endian)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;supply&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBigUint64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;36&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Byte 44: Decimals (u8)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;decimals&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUint8&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;44&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Bytes 45-76: Freeze authority&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;freezeAuthBytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;45&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;77&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;mintAuthority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;base58Decoder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mintAuthBytes&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nx"&gt;supply&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;decimals&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;freezeAuthority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;base58Decoder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;freezeAuthBytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
&lt;strong&gt;Key gotcha:&lt;/strong&gt; The &lt;code&gt;true&lt;/code&gt; parameter means little-endian. Solana uses little-endian (LSB first). Get this wrong and your numbers are garbage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ❌ WRONG - big-endian&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;supply&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBigUint64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;36&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// Incorrect!&lt;/span&gt;

&lt;span class="c1"&gt;// ✅ CORRECT - little-endian&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;supply&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBigUint64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;36&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// Correct&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9dqztjen111heslradqr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9dqztjen111heslradqr.png" alt="Method 2: Manual byte-level parsing" width="800" height="722"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv7gnn8lscvnmhacqe1te.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv7gnn8lscvnmhacqe1te.png" alt="The rest of method 2" width="736" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Complete control&lt;/li&gt;
&lt;li&gt;✅ Learn exactly how serialization works&lt;/li&gt;
&lt;li&gt;✅ Works for any binary format&lt;/li&gt;
&lt;li&gt;✅ No dependencies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❌ Easy to get offsets wrong&lt;/li&gt;
&lt;li&gt;❌ Tedious for complex structures&lt;/li&gt;
&lt;li&gt;❌ No type checking&lt;/li&gt;
&lt;li&gt;❌ Must handle endianness manually&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Method 3: RPC's jsonParsed Format
&lt;/h2&gt;

&lt;p&gt;Let Solana's RPC do the parsing for you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;decodeViaRpc&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.mainnet-beta.solana.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;WRAPPED_SOL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;So11111111111111111111111111111111111111112&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Use getParsedAccountInfo instead of getAccountInfo&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;accountInfo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getParsedAccountInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PublicKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;WRAPPED_SOL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;accountInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Method 3: RPC jsonParsed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Supply:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;supply&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Decimals:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;decimals&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mint Authority:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkh1b9fu8zk5v3ses2c1u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkh1b9fu8zk5v3ses2c1u.png" alt="Method 3: RPC jsonParsed Format" width="685" height="564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ One RPC call&lt;/li&gt;
&lt;li&gt;✅ Automatic parsing&lt;/li&gt;
&lt;li&gt;✅ Type-safe JSON response&lt;/li&gt;
&lt;li&gt;✅ Easiest to implement&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❌ Only works for known program types&lt;/li&gt;
&lt;li&gt;❌ Depends on RPC node supporting it&lt;/li&gt;
&lt;li&gt;❌ Can't inspect raw data&lt;/li&gt;
&lt;li&gt;❌ Slower than local parsing&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Comparison: Real Results
&lt;/h2&gt;

&lt;p&gt;I tested all three methods on Wrapped SOL (&lt;code&gt;So11111111...&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Method 1 (Codec):      Supply: 10234567890000000000n, Decimals: 9
Method 2 (Manual):     Supply: 10234567890000000000n, Decimals: 9
Method 3 (RPC):        Supply: "10234567890000000000", Decimals: 9

Status: ✅ All three match!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8ka0lnear60thbzwce8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8ka0lnear60thbzwce8.png" alt="Comparison &amp;amp; Verification" width="800" height="701"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Deciding Which to Use
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use Method 1 (Codec)&lt;/strong&gt; if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You're working with SPL types (tokens, mints, associated accounts)&lt;/li&gt;
&lt;li&gt;You want type safety&lt;/li&gt;
&lt;li&gt;You're okay with an external dependency&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Method 2 (Manual)&lt;/strong&gt; if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You're parsing custom program data&lt;/li&gt;
&lt;li&gt;You want to understand the binary format&lt;/li&gt;
&lt;li&gt;You need maximum control&lt;/li&gt;
&lt;li&gt;You're building low-level tools&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Method 3 (RPC)&lt;/strong&gt; if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You're building quick scripts&lt;/li&gt;
&lt;li&gt;The RPC node supports parsing your account type&lt;/li&gt;
&lt;li&gt;Performance isn't critical&lt;/li&gt;
&lt;li&gt;You just want the data, not the details&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Real-World Example: Parsing Token Account Data
&lt;/h2&gt;

&lt;p&gt;Here's where it gets practical. A token account has a different structure than a mint. Let's decode one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;decodeTokenAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.mainnet-beta.solana.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;accountInfo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAccountInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PublicKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;view&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DataView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;accountInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Token account structure:&lt;/span&gt;
  &lt;span class="c1"&gt;// 0-31:   Mint (32 bytes)&lt;/span&gt;
  &lt;span class="c1"&gt;// 32-63:  Owner (32 bytes)&lt;/span&gt;
  &lt;span class="c1"&gt;// 64-71:  Amount (u64)&lt;/span&gt;
  &lt;span class="c1"&gt;// 72:     Decimals (u8)&lt;/span&gt;
  &lt;span class="c1"&gt;// 73-103: Delegate (32 bytes)&lt;/span&gt;
  &lt;span class="c1"&gt;// etc.&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBigUint64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;decimals&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUint8&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;72&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;realAmount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;decimals&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Token Balance: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;realAmount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8lxa71e2nu820h065err.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8lxa71e2nu820h065err.png" alt="Summary Table" width="740" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Key Insight
&lt;/h2&gt;

&lt;p&gt;Borsh serialization is deterministic: given the same account data, all three methods produce identical results. The difference is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Implementation complexity&lt;/strong&gt; (codec &amp;gt; RPC &amp;gt; manual)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Type safety&lt;/strong&gt; (codec &amp;gt; manual &amp;gt; RPC)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance&lt;/strong&gt; (manual &amp;gt; codec &amp;gt; RPC)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexibility&lt;/strong&gt; (manual &amp;gt; codec &amp;gt; RPC)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Choose based on your use case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical Debugging
&lt;/h2&gt;

&lt;p&gt;When parsing fails, debug systematically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Raw data length:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;First 10 bytes:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;view&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DataView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBigUint64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Offset &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; (0x&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;)`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Often the issue is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Wrong offset (miscounted bytes)&lt;/li&gt;
&lt;li&gt;Wrong endianness (used &lt;code&gt;false&lt;/code&gt; instead of &lt;code&gt;true&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Wrong data type (u32 instead of u64)&lt;/li&gt;
&lt;li&gt;Missing discriminators or padding&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Check the SPL source code for the exact account layout.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Full Example
&lt;/h2&gt;

&lt;p&gt;Here's a complete script using all three methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;PublicKey&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@solana/web3.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getMintDecoder&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@solana-program/token&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;base58Decoder&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@solana/codecs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;WRAPPED_SOL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;So11111111111111111111111111111111111111112&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;compareDecodingMethods&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.mainnet-beta.solana.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;accountInfo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAccountInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PublicKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;WRAPPED_SOL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Method 1: Codec&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mintDecoder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getMintDecoder&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;m1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;mintDecoder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;accountInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Method 2: Manual&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;view&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DataView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;accountInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;m2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;supply&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBigUint64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;36&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;decimals&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUint8&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;44&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="c1"&gt;// Method 3: RPC&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getParsedAccountInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PublicKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;WRAPPED_SOL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;m3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Supply Comparison:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Codec:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;supply&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Manual:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;supply&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;RPC:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;supply&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;compareDecodingMethods&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Challenge
&lt;/h2&gt;

&lt;p&gt;Try parsing a token account you own:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Get the account address&lt;/li&gt;
&lt;li&gt;Fetch it via RPC&lt;/li&gt;
&lt;li&gt;Decode using all three methods&lt;/li&gt;
&lt;li&gt;Verify they match&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Understanding this deepens your grasp of Solana's data model.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Next in this series:&lt;/strong&gt; Post 4 covers Solana's System Program — the kernel-level program that owns every wallet and enforces the rules that hold the whole network together.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Series: The Account Model Foundation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Part 1: &lt;a href="https://dev.to/lymah/the-solana-account-model-explained-everything-is-an-account-3g48"&gt;The Account Model Explained&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Part 2: &lt;a href="https://dev.to/lymah/building-a-solana-account-explorer-query-on-chain-data-like-a-database-293d"&gt;Building an Account Explorer&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Part 3: Decoding Account Data &lt;em&gt;(this post)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Part 4: System Program Deep Dive &lt;em&gt;(coming May 22)&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Which method do you prefer? Let me know in the comments!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Part of the &lt;a href="https://www.mlh.com/events/100-days-of-solana/challenges" rel="noopener noreferrer"&gt;100 Days of Solana&lt;/a&gt; Epoch 1 Writing Challenge.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>100daysofsolana</category>
      <category>web3</category>
      <category>writing</category>
      <category>learning</category>
    </item>
    <item>
      <title>Building a Solana Account Explorer: Query On-Chain Data Like a Database</title>
      <dc:creator>Lymah</dc:creator>
      <pubDate>Mon, 18 May 2026 17:58:44 +0000</pubDate>
      <link>https://dev.to/lymah/building-a-solana-account-explorer-query-on-chain-data-like-a-database-293d</link>
      <guid>https://dev.to/lymah/building-a-solana-account-explorer-query-on-chain-data-like-a-database-293d</guid>
      <description>&lt;h2&gt;
  
  
  From Concept to Code
&lt;/h2&gt;

&lt;p&gt;In &lt;a href="https://dev.to/lymah/the-solana-account-model-explained-everything-is-an-account-3g48"&gt;Part 1 of this series&lt;/a&gt;, I explained that everything on Solana is an account with five fields: &lt;code&gt;lamports&lt;/code&gt;, &lt;code&gt;data&lt;/code&gt;, &lt;code&gt;owner&lt;/code&gt;, &lt;code&gt;executable&lt;/code&gt;, and &lt;code&gt;rent_epoch&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That's the theory. But theory only sticks when you run it against real data.&lt;/p&gt;

&lt;p&gt;So I built a command-line account explorer that queries any Solana address and prints all five fields in a readable format. In this post, I'll walk you through how I built it, what I learned from the output, and the three things that genuinely surprised me when I started querying real accounts.&lt;/p&gt;

&lt;p&gt;By the end, you'll have a tool you can run against any address on the network — and a much sharper intuition for what's actually living on-chain.&lt;/p&gt;




&lt;h2&gt;
  
  
  What We're Building
&lt;/h2&gt;

&lt;p&gt;A CLI tool that takes any Solana address and returns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Balance in both SOL and lamports&lt;/li&gt;
&lt;li&gt;Owner program (with friendly names for known programs)&lt;/li&gt;
&lt;li&gt;Whether it's executable or a data account&lt;/li&gt;
&lt;li&gt;Data size and a hex preview of the first bytes&lt;/li&gt;
&lt;li&gt;Rent epoch&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's what the output looks like against three different account types:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A wallet account:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6bopgz3wf4lmzp28l5rq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6bopgz3wf4lmzp28l5rq.png" alt="Wallet account" width="800" height="645"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Token Program:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdxh6hjlx7zxguwtc6sp3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdxh6hjlx7zxguwtc6sp3.png" alt="Toke program" width="800" height="672"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;The System Program itself:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyy88vyc5pq5qkzuforqi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyy88vyc5pq5qkzuforqi.png" alt="System Program" width="800" height="683"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Same five fields. Three completely different accounts. Let's build it.&lt;/p&gt;


&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;solana-account-explorer
&lt;span class="nb"&gt;cd &lt;/span&gt;solana-account-explorer
npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
npm &lt;span class="nb"&gt;install&lt;/span&gt; @solana/kit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Create &lt;code&gt;explorer.mjs&lt;/code&gt; — we use &lt;code&gt;.mjs&lt;/code&gt; for ES module syntax with top-level &lt;code&gt;await&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Full Code
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createSolanaRpc&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@solana/kit&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Known program addresses mapped to friendly names&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;KNOWN_PROGRAMS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;11111111111111111111111111111111&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;System Program&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Token Program&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;TokenzQdsByhw9vBi3wq3kQtj78oYCa9PzPgcGW8K3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Token Program (SPL-2022)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ATokenGPvbdGVqstVQmcLsNZAqeEoctVrGMMXuLYDJ&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Associated Token Program&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;9xQeWvG816bUx9EPjHmaT23yfBYP5ihLeLSKcsFqrXa&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Raydium Program&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;JUP4Fb2cqiRUcaTHdrPC8h2gNsszFildan3xnjnZALn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Jupiter Aggregator&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;DezXAZ8z7PnrnRJjz3wXBoRgixVpdZuvXAfqJ7DKPs1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Magic Eden&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;BPFLoaderUpgradeab1e11111111111111111111111&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;BPF Loader (Program Upgrades)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;BPFLoader2111111111111111111111111111111111&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;BPF Loader&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Get address from command line argument&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;❌ Error: No address provided!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Usage: node explorer.mjs &amp;lt;solana-address&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Connect to devnet&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rpc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createSolanaRpc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.devnet.solana.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;exploreAccount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;🔍 Solana Account Explorer&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;━&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

    &lt;span class="c1"&gt;// Fetch balance and account info in parallel&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;accountInfo&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
      &lt;span class="nx"&gt;rpc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBalance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
      &lt;span class="nx"&gt;rpc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAccountInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="p"&gt;]);&lt;/span&gt;

    &lt;span class="c1"&gt;// Convert lamports to SOL&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;solBalance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;e9&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toFixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`\n📍 Address:\n   &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\n`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`💰 Balance:\n   &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;solBalance&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; SOL (&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; lamports)\n`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;accountInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ℹ️  This address does not exist on the blockchain yet.&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;━&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Resolve owner to friendly name if known&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;accountInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ownerName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;KNOWN_PROGRAMS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`👤 Owner:\n   &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;ownerName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\n`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Executable flag&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isExecutable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;accountInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;executable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="s2"&gt;`⚙️  Executable:\n   &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;isExecutable&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Yes (Program Account)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No (Data/Wallet Account)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\n`&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Rent epoch&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`📅 Rent Epoch:\n   &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;accountInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rentEpoch&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\n`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Data size and hex preview&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dataLength&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;accountInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`📦 Data:\n   Size: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;dataLength&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; bytes\n`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dataLength&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;displaySize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dataLength&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dataSample&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;accountInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;displaySize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hex&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`   First &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;displaySize&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; bytes (hex):`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`   &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;dataSample&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dataLength&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;displaySize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`   ... (&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;dataLength&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;displaySize&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; more bytes omitted)`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`   (empty)\n`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;━&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;❌ Error exploring account:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;exploreAccount&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Run it against any address:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Query the System Program&lt;/span&gt;
node explorer.mjs 11111111111111111111111111111111

&lt;span class="c"&gt;# Query the Token Program&lt;/span&gt;
node explorer.mjs TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA

&lt;span class="c"&gt;# Query your own wallet&lt;/span&gt;
node explorer.mjs &amp;lt;your-wallet-address&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  What the Output Taught Me
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The System Program owns itself — sort of
&lt;/h3&gt;

&lt;p&gt;When I queried &lt;code&gt;11111111111111111111111111111111&lt;/code&gt;, I expected to see the System Program as its own owner. Instead I got &lt;code&gt;NativeLoader&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That threw me until I understood: &lt;code&gt;NativeLoader&lt;/code&gt; is the Solana runtime's built-in loader. It owns the System Program the same way a kernel owns its own system calls. The System Program is baked into the runtime at a level below the normal account ownership model. It's not a program that was deployed — it was compiled into the validator itself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key difference from Token Program:&lt;/strong&gt; The Token Program is owned by &lt;code&gt;BPF Loader (Program Upgrades)&lt;/code&gt;, which means it was deployed like any other program and can be upgraded. The System Program cannot — it's part of the protocol.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Token Program is only 48 bytes — but controls everything
&lt;/h3&gt;

&lt;p&gt;Look at the Token Program output: 48 bytes of data. That's it. 48 bytes of what turns out to be a pointer — not the actual bytecode.&lt;/p&gt;

&lt;p&gt;This is because the Token Program uses the upgradeable BPF loader pattern. The 48 bytes in the main account point to a separate &lt;em&gt;program data account&lt;/em&gt; that holds the actual bytecode. The split exists so the program can be upgraded without changing its address.&lt;/p&gt;

&lt;p&gt;This was my first real encounter with indirection on Solana — the account you call isn't always where the code lives.&lt;/p&gt;

&lt;h3&gt;
  
  
  A wallet with 0 bytes of data is a complete account
&lt;/h3&gt;

&lt;p&gt;The wallet output shows &lt;code&gt;Size: 0 bytes&lt;/code&gt; and &lt;code&gt;(empty)&lt;/code&gt; for data. In Web2 terms that looks like a broken record — a row with no content. But on Solana, a wallet doesn't need data. Its entire purpose is to hold lamports. The &lt;code&gt;owner&lt;/code&gt; field (System Program) and the &lt;code&gt;lamports&lt;/code&gt; field are all it needs to function.&lt;/p&gt;

&lt;p&gt;This is the account model in action: the structure is always the same, but some fields are intentionally empty depending on the account's purpose.&lt;/p&gt;




&lt;h2&gt;
  
  
  Three Things Worth Noticing in Your Own Queries
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Compare executable accounts vs data accounts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run the explorer on a program address and a wallet address back to back. Notice how &lt;code&gt;executable: Yes&lt;/code&gt; vs &lt;code&gt;executable: No&lt;/code&gt; changes everything about what that account does — even though both have identical field structures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Watch the owner field&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every account you'll ever encounter is owned by exactly one program. Query five random addresses and look at what owns them. You'll start recognizing patterns: wallets owned by System Program, tokens owned by Token Program, NFT metadata owned by Metaplex's program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The data field is where all the interesting stuff hides&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The hex bytes in the data field aren't random — they're structured binary data that each program knows how to decode. That wall of hex is actually a token supply, or a price oracle, or a governance vote. Decoding that raw data is exactly what Post 3 covers.&lt;/p&gt;




&lt;h2&gt;
  
  
  The &lt;code&gt;KNOWN_PROGRAMS&lt;/code&gt; Map — Why It Matters
&lt;/h2&gt;

&lt;p&gt;One design choice worth explaining: the &lt;code&gt;KNOWN_PROGRAMS&lt;/code&gt; lookup table at the top of the file.&lt;/p&gt;

&lt;p&gt;Without it, the owner field just shows a raw base58 address like &lt;code&gt;BPFLoaderUpgradeab1e11111111111111111111111&lt;/code&gt;. With it, you see &lt;code&gt;BPF Loader (Program Upgrades)&lt;/code&gt; — immediately meaningful.&lt;/p&gt;

&lt;p&gt;This is the same pattern Solana Explorer uses under the hood. As you build on Solana, you'll develop your own mental map of which program addresses do what. This table is a starter version of that map. Add to it as you encounter new programs.&lt;/p&gt;




&lt;h2&gt;
  
  
  Try It Yourself
&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;# Copy the code above into explorer.mjs, then:&lt;/span&gt;
npm &lt;span class="nb"&gt;install&lt;/span&gt; @solana/kit

&lt;span class="c"&gt;# Try these three to see the contrast clearly:&lt;/span&gt;
node explorer.mjs 11111111111111111111111111111111
node explorer.mjs TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
node explorer.mjs SysvarC1ock11111111111111111111111111111111
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each one will show you the same five fields, completely different values. That contrast is worth seeing with your own eyes.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Next
&lt;/h2&gt;

&lt;p&gt;This explorer shows you the raw bytes in the &lt;code&gt;data&lt;/code&gt; field — but doesn't tell you what they mean. A token mint's data field contains supply, decimals, and mint authority. A governance account's data field contains vote counts and proposal state. All of it is encoded in binary.&lt;/p&gt;

&lt;p&gt;Post 3 covers exactly that: three methods for decoding raw Solana account data, from manual buffer parsing to using Anchor's IDL to using pre-built deserializers. That's where the hex bytes stop being noise and start being information.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Series: The Account Model Foundation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Part 1: &lt;a href="https://dev.to/lymah/the-solana-account-model-explained-everything-is-an-account-3g48"&gt;The Account Model Explained&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Part 2: Building an Account Explorer &lt;em&gt;(this post)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Part 3: Decoding Account Data &lt;em&gt;(coming May 20)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Part 4: System Program Deep Dive &lt;em&gt;(coming May 22)&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;What address did you query first? Drop it in the comments — I'd love to see what people are exploring.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Part of the &lt;a href="https://www.mlh.com/events/100-days-of-solana/challenges" rel="noopener noreferrer"&gt;100 Days of Solana&lt;/a&gt; Epoch 1 Writing Challenge.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>100daysofsolana</category>
      <category>web3</category>
      <category>learning</category>
      <category>writing</category>
    </item>
  </channel>
</rss>
