今日已更新 498 条资讯 | 累计 20470 条内容
关于我们

Arc 11 Catch-Up: Composing Solana Programs with CPIs

Matthew Revell 2026年07月16日 20:46 0 次阅读 来源:Dev.to

Arc 11 covered Days 71–77 of Epoch 3, and it was all about Cross-Program Invocations. In Arc 9, we wrote our first Solana program. In Arc 10, we gave that program a more useful state model with Program Derived Addresses. But our programs were still mostly working alone. They could read and update their own accounts, enforce their own constraints, and respond to instructions sent by a client. They could not directly change state owned by another program or bypass the rules that program enforced. That is an important part of Solana’s security model. The System Program owns the rules for creating accounts and transferring lamports. Token-2022 owns the rules for mints, token accounts, supply, and mint authorities. If our program needs one of those capabilities, it calls the program that owns the operation. That call is a Cross-Program Invocation, or CPI. The Web2 comparison is a service-to-service API call. One service sends a request through another service’s public interface, and the receiving service applies its own rules. A CPI works in a similar way, with one important difference: the outer and inner instructions execute as part of the same Solana transaction. If the inner call fails, the state changes made by the outer instruction are rolled back too. That combination of clear program boundaries and atomic execution is what makes Solana programs composable. Our first CPI called the System Program The arc began with the smallest useful CPI we could build. Our Anchor program accepted a sender, a recipient, and an amount of SOL to transfer. But the program did not edit the sender’s balance directly. Instead, it called the System Program’s transfer instruction. That distinction matters. Accounts on Solana are owned by programs, and the owner program controls how their data may be changed. Our program could not simply reproduce the effect of a System Program transfer by adjusting balances itself. It had to ask the System Program to perform the operation. Every CPI need

本文内容来源于互联网,版权归原作者所有
查看原文