Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Add more notes on CPI
Browse files Browse the repository at this point in the history
  • Loading branch information
urani-engineering-helper authored Mar 27, 2024
1 parent 92db2a6 commit a330fc2
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion chapters/03_anchor.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,39 @@ pub enum MyError {

---

### Privilege Extension
### Cross Program Invocations (CPIs)

<br>

* CPIs enable the composability of Solana programs, allowing developers to utilize and build on the instruction of existing programs.

* To execute CPIs, use `invoke` or `invoke_signed` from the `solana_program` crate:

<br>

```rust
// Used when there are not signatures for PDAs needed
pub fn invoke(
instruction: &Instruction,
account_infos: &[AccountInfo<'_>]
) -> ProgramResult

// Used when a program must provide a 'signature' for a PDA, hence the signer_seeds parameter
pub fn invoke_signed(
instruction: &Instruction,
account_infos: &[AccountInfo<'_>],
signers_seeds: &[&[&[u8]]]
) -> ProgramResult
```

<br>

* To make a CPI, you must specify and construct an instruction on the program being invoked and supply a list of accounts necessary for that instruction.
- If a PDA is required as a signed, the `signers_seeds` must also be provided with `invoke_signed`.

<br>

#### Privilege Extension

<br>

Expand Down

0 comments on commit a330fc2

Please sign in to comment.