I'm developing a on-chain Solana program with Anchor. Let's call this Program A. Inside an instruction of Program A, it'll perform a CPI to invoke Program B. I want to pass Program A as an account during the CPI.

My question is: should I have to also include Program A itself as an account when sending the transaction from the client side? This is somewhat funny, because I have to define a #[Accounts] struct for Program A like this:

pub struct FooInstruction<'info> {
    /// CHECK: We only need the Pubkey of this account
    #[account(address = crate::ID)]
    pub this_program: UncheckedAccount<'info>,

    pub program_b: Program<'info, ProgramB>,

What the runtime is executing now is exactly this_program, and I should still pass in this_program?

1 Answer 1


Indeed, the transaction should be initiated with knowledge of all relevant accounts. In other words, all accounts that will be utilized should be identified during the creation of the transaction. This is necessary as the CPI requires program account info, which is not retrievable at runtime. Therefore, it's essential to provide this information during the making transaction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.