Note
This is the Anchor v2 copy of this example. Every anchor command on this page
needs the v2 CLI: cargo install anchor-cli --version 2.0.0-rc.4 --locked (avm has
no prebuilt binary for this pre-release). The Anchor v1 version of this example is in
../anchor-v1.
Invoke another program from this one (hand program calls lever program) using CPI.
See also: Cross Program Invocation overview and the repository catalog.
- Cross-program invocation (CPI)
- Composing multiple programs in one transaction
declare_program!CPI functions write the instruction data into a fixed-capacity buffer the caller supplies onchain.pull_leversizes its buffer for a name of up toMAX_NAME_LEN(32) bytes and refuses a longer one withNameTooLong.
From this directory (basics/cross-program-invocation/anchor/):
anchor buildPrerequisites: Agave CLI (version in Anchor.toml [toolchain]), Anchor.
Tests run in-process with LiteSVM. No local validator.
anchor testThis runs cargo test as configured in Anchor.toml. Tests call instruction handlers and check onchain state.
Read the program programs/ source and Anchor.toml for deployed program IDs. For deployment, use anchor build && anchor program deploy against your target cluster.