One of Solana's most powerful features is that programs can call other programs. This is called a Cross-Program Invocation, or CPI. If you have ever wondered how a single transaction can swap tokens, update a balance, and mint an NFT all at once, CPIs are the answer.
What Is a CPI?
A Cross-Program Invocation happens when one on-chain program invokes an instruction on another program during the same transaction. Think of it like one app calling another app's function. The calling program passes along the accounts and data the target program needs, and the target program runs as if it had been called directly.
For example, almost every DeFi protocol on Solana relies on CPIs to the SPL Token Program to actually move tokens. Your favorite decentralized exchange doesn't reinvent token transfers — it just calls the standard token program.
Why CPIs Matter
- Composability: Programs build on each other like Lego bricks, so developers reuse trusted code instead of rewriting it.
- Atomicity: All steps happen in one transaction. If any part fails, the entire thing rolls back — no half-finished states.
- Security: Core logic lives in a few battle-tested programs rather than being copied everywhere.
Signer Privileges and PDAs
When a program makes a CPI, it can pass along the signer privileges it received. Programs can also sign on behalf of Program Derived Addresses (PDAs) using seeds, which lets a program control accounts without a private key. This is how vaults, escrows, and automated market makers move funds safely.
CPIs are limited to a depth of four nested calls. This cap prevents runaway recursion and keeps transactions predictable.
Takeaway
Cross-Program Invocations are the glue of the Solana ecosystem. They let independent programs cooperate in a single atomic transaction, making the network more modular, secure, and composable. The next time a single click swaps, stakes, and rewards you all at once, you'll know CPIs are quietly doing the work behind the scenes.