Escrow patterns
An escrow holds assets in a program-controlled account, usually a token account whose authority is a PDA, until agreed conditions are met. The usual lifecycle is make (deposit and record terms), take (counterparty pays and receives), and refund or cancel (the maker reclaims). Security depends on checking every account relationship and closing accounts so rent is returned.
Reference: Solana program examples (escrow) · Anchor docs
Real code, line by line
1 excerpts from different projects. Each caption links the exact lines at the fork's pinned commit. The notes below each excerpt explain the lines that matter.
escrow/programs/mm_escrow/src/instructions/cancel.rs L37–62 @ ca496be · Apache-2.0 · original let escrow_signer_seeds: &[&[&[u8]]] = &[&[ b"escrow", self.escrow.authority.as_ref(), self.escrow.product_seed.as_str().as_bytes(), &[self.escrow.bump], ]]; transfer( CpiContext::new_with_signer( self.token_program.to_account_info(), cpi_accounts, escrow_signer_seeds, ), self.escrowed_x_tokens.amount, ) } pub fn close_escrow(&self) -> Result<()> { let cpi_accounts = CloseAccount { account: self.escrowed_x_tokens.to_account_info(), destination: self.seller.to_account_info(), authority: self.escrow.to_account_info(), }; let escrow_signer_seeds: &[&[&[u8]]] = &[&[ b"escrow", self.escrow.authority.as_ref(),- Line 41
&[self.escrow.bump],: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 44
CpiContext::new_with_signer(: Makes a CPI signed by a PDA. The signer seeds prove the program controls that address.
Go further
- peer-pay: explore the full project
- Next lesson: NFTs with Metaplex