In the anchor-lang
docs it says,
The features = ["cpi"] is used so we can not only use puppet's types but also its instruction builders and cpi functions. Without those, we would have to use low level solana syscalls. Fortunately, anchor provides abstractions on top of those. By enabling the cpi feature, the puppet-master program gets access to the puppet::cpi module. Anchor generates this module automatically and it contains tailor-made instructions builders and cpi helpers for the program.
https://www.anchor-lang.com/docs/cross-program-invocations
In the examples I've found, the programs to CPI into are also included and you have to specify the path in Cargo.toml
.
[dependencies]
callee = { path = "../callee", features = ["cpi"] }
https://github.com/coral-xyz/anchor/blob/master/tests/cpi-returns/programs/caller/Cargo.toml#L20
[dependencies]
puppet = { path = "../puppet", features = ["cpi"] }
- Does
features = ["cpi"]
only work if you also having both programs? - Can the feature be used with Anchor programs that you don't have the code to?
- Does the feature only work with Anchor programs, or can it also work with Native programs?
For example, is there a way to use the features = ["cpi"]
with programs cloned in Anchor.toml
for to make CPIs to for testing?
[test.validator]
url = "https://api.mainnet-beta.solana.com"
[[test.validator.clone]]
address = "7NL2qWArf2BbEBBH1vTRZCsoNqFATTddH6h8GkVvrLpG"
More generally, I'm trying to figure out how to make CPIs with CpiContext
to programs other than the Token program using the anchor_spl
crate.