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.
ownerOf(tokenId) and forwards the call.A PDA for each NFT
A 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.
| 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.
#[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 for the transfer itself.
Side by side
Pitfalls to check
Review these before you deploy a wallet program.