> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# ERC6551 on Solana: Token Bound Accounts

> Give an NFT its own wallet on Solana with a PDA derived from the NFT's mint address and a program that authorizes the current holder.

ERC6551 gives every NFT a smart contract account that the NFT's owner controls.
On Solana, you get the same result with a PDA derived from the NFT's mint
address and a program that lets the current holder act for it.

## What ERC6551 defines

ERC6551 adds a registry contract that deploys an account contract for any ERC721
token. The account's address is deterministic, and its code lets whoever owns
the NFT execute calls from it. Assets held by the account move with the NFT when
it is sold.

<Steps>
<Step title="Registry creates an account">

The address is computed from the implementation, the chain ID, the NFT contract,
the token ID, and a salt.

</Step>
<Step title="Account holds assets">

It can receive tokens and other NFTs.

</Step>
<Step title="Owner executes">

The account checks `ownerOf(tokenId)` and forwards the call.

</Step>
<Step title="NFT is sold">

The new owner controls the account and everything in it.

</Step>
</Steps>

## A PDA for each NFT

A [PDA](/developers/docs/core/pda) is an address derived from a program ID and
seeds. Use the NFT's mint address as a seed, and each NFT gets one deterministic
address. No registry transaction is needed: you can derive the address and send
SOL to it right away. Token accounts owned by the PDA still have to be created
and funded.

```mermaid
flowchart TD
    P["Wallet program<br/>Verifies the holder, then signs for the PDA"]
    P -->|derives| P0["NFT wallet PDA<br/>Seeds: a prefix and the mint address"]
    P -->|derives| P1["Token accounts<br/>Owned by the PDA"]
    P -->|derives| P2["SOL balance<br/>Held by the PDA"]
```

<div className="sol-mermaid" data-fallback="mermaid" data-mermaid="a7f6f7b2ca47">
  <img className="block dark:hidden" src="/docs-assets/assets/docs/mermaid/a7f6f7b2ca47-light.svg" alt="One program gives every NFT a wallet." />

  <img className="hidden dark:block" src="/docs-assets/assets/docs/mermaid/a7f6f7b2ca47.svg" alt="One program gives every NFT a wallet." />

  <img className="block dark:hidden" src="/docs-assets/assets/docs/mermaid/a7f6f7b2ca47-sm-light.svg" alt="One program gives every NFT a wallet." />

  <img className="hidden dark:block" src="/docs-assets/assets/docs/mermaid/a7f6f7b2ca47-sm.svg" alt="One program gives every NFT a wallet." />
</div>

<p className="sol-caption">One program gives every NFT a wallet.</p>

| ERC6551 | Solana |
| --- | --- |
| Registry contract | PDA derivation, with no transaction |
| Account implementation contract | Your wallet program, deployed once |
| `ownerOf(tokenId)` check | A check that the signer's token account holds the NFT |
| `execute()` | An instruction that signs for the PDA in a CPI |

## Authorize the current holder

The program must prove that the signer holds the NFT before it acts for the PDA.
With Anchor, account constraints express the checks: the mint is an NFT with a
supply of 1 and 0 decimals, the token account belongs to the signer, it is for
this mint, and it holds the single unit.

```rust
#[derive(Accounts)]
pub struct Execute<'info> {
    pub holder: Signer<'info>,

    // Only an NFT qualifies: one unit, no decimals.
    #[account(
        constraint = nft_mint.supply == 1 && nft_mint.decimals == 0 @ WalletError::NotAnNft,
    )]
    pub nft_mint: InterfaceAccount<'info, Mint>,

    // Proves that the signer holds the NFT right now.
    #[account(
        token::mint = nft_mint,
        token::authority = holder,
        constraint = nft_token_account.amount == 1 @ WalletError::NotHolder,
    )]
    pub nft_token_account: InterfaceAccount<'info, TokenAccount>,

    /// CHECK: The NFT's wallet. Only this program can sign for it.
    #[account(seeds = [b"nft-wallet", nft_mint.key().as_ref()], bump)]
    pub nft_wallet: UncheckedAccount<'info>,
}
```

After the checks pass, the instruction calls another program with
`CpiContext::new_with_signer` and the PDA's seeds. For example, it can transfer
tokens out of a token account that the PDA owns. See [token
CPIs](/developers/docs/tokens/advanced/cpi) for the transfer itself.

## Side by side

<Columns cols={2}>
<Card title="ERC6551">

- A registry deploys one account contract per NFT.
- The account can call any contract with arbitrary calldata.
- Works with existing ERC721 collections without changes.

</Card>
<Card title="Solana">

- One program serves every NFT, and deriving a PDA needs no transaction.
- The program defines which actions the PDA can take, since every CPI needs its
  accounts listed.
- Works with any NFT that has a mint address, without changing the NFT.

</Card>
</Columns>

## Pitfalls to check

Review these before you deploy a wallet program.

- Check that the mint is an NFT: a supply of 1, 0 decimals, and no mint
  authority that can issue more. For Metaplex NFTs, the master edition holds
  that authority. Otherwise more than one holder can pass the check for the same
  wallet.
- Check the amount, the mint, and the owner of the NFT token account. A token
  account with a zero balance still exists after the NFT is sold.
- Fix the seed prefix in the program so a caller cannot derive a PDA for a
  different purpose.
- Limit which programs the PDA can call, or validate each target program ID. An
  open-ended execute instruction lets the wallet PDA sign for any program a
  caller passes in, including a malicious one supplied by a front end.
- Warn buyers that the wallet's contents move with the NFT. A seller can empty
  the wallet immediately before a sale, so have the buyer's transaction check
  the contents.
- For Metaplex Core or compressed NFTs, verify ownership through that standard's
  account or proof, since they have no token account.

## Next steps

<Columns cols={3}>
<Card title="Program Derived Addresses" href="/developers/docs/core/pda" arrow>

Learn how seeds and bumps derive an address.

</Card>
<Card title="ERC721 on Solana" href="/developers/docs/migrate-to-solana/ethereum/standards/erc721">

Compare the NFT standards available on Solana.

</Card>
<Card title="ERC4337 on Solana" href="/developers/docs/migrate-to-solana/ethereum/standards/erc4337">

Build a smart wallet with the same PDA pattern.

</Card>
</Columns>
