Quantcast
Channel: How can I do one cross-program-invocation with multiple instructions? - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 2

How can I do one cross-program-invocation with multiple instructions?

$
0
0

in a nutshell I'm wondering how to send one CPI call with a vector of Instructions.

Here's an example:

I noticed there's a function in the solana_program Rust crate called:

solana_program::system_instruction::transfer_many

It's parameters & return type are as follows:

pub fn transfer_many(    from_pubkey: &Pubkey,    to_lamports: &[(Pubkey, u64)]) -> Vec<Instruction>

This will obviously return to me a vector of Instruction types, but as far as I can tell invoke and invoke_signed are designed for one instruction at a time.

How can I use this vector of instructions dynamically, say if I want my program to transfer 3 different amounts to 3 different accounts in one transaction?

One can infer that you could iterate over the vector and use invoke, but that raises three concerns:

  1. This seems sort of strange.
  2. How do I determine, for each invoke call, what accounts to pass?
  3. How do I determine, for each invoke_signed call, what seeds to sign with?

Is there some way to do a single CPI that will send a transaction with multiple instructions?

Link to function: https://docs.rs/solana-program/latest/solana_program/system_instruction/fn.transfer_many.html


Viewing all articles
Browse latest Browse all 2

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>