Skip to main content
Cross-Program Invocations (CPIs) allow your program to call instructions on other programs. This is essential for composability on Solana.

What are CPIs?

CPIs enable your program to:
  • Call functions in other programs (like Token Program, System Program)
  • Transfer SOL or tokens
  • Create and manage accounts on behalf of PDAs
  • Build complex composable applications

Making a CPI

Anchor provides the CpiContext type for making CPIs:

CPI with signers

When a PDA needs to sign a CPI, use CpiContext::new_with_signer:

Common CPI examples

Transferring SOL

Creating accounts

Minting tokens

Using declare_program! for CPIs

For external programs, use declare_program! to generate type-safe CPI helpers:

CPI return values

Since Solana v1.16, CPIs can return values:

Complete example

Best practices

Validate CPI accounts - Always verify accounts passed to CPIs belong to the expected programs.
Check return values - When CPIs return data, validate the returning program ID matches expectations.
Be aware of compute limits - CPIs consume compute units from your program’s budget.

Next steps

SPL integrations

Learn about anchor-spl CPI helpers

declare_program!

Generate type-safe CPI helpers