3

I've been working on ways to process transactions within some anchor functions and I ended up with this below. It works perfectly however I noticed that the signer array is empty and was curious why it isn't necessary for me to pass in anything there.

let transfer_instruction: Instruction = system_instruction::transfer(user.key,item_account.to_account_info().key,lamports);
solana_program::program::invoke_signed(
    &transfer_instruction,
    &[
         user.to_account_info(),
         item_account.to_account_info().clone(),
         ctx.accounts.system_program.to_account_info(),
     ],
     &[], <<-- No signer needed here?
)?;

Since it works without it, my following question would be, then in what scenario do we need to pass it here as I've manage to add this type of transactions throughout my app and have never needed to add the signer.

1 Answer 1

3

You'd only need to populate the signers argument array if a program-derived-address owned by your program is a required signer for that instruction invocation. PDAs are referred to as off-curve address since they don't have an associated private key and thus can only sign via the program that owns them(by passing their seeds to the array you pointed to above).

However, this is not the case in this example since the required signer(user in this case), the from pubkey, is NOT a PDA. It is a normal on-curve address with an associated private key, which means that its signature is obtained on the client-side instead.

3
  • But the above code works without any data in the signer array. Maybe I'm not understand what you mean. It works in many places throughout my app (at least testing through localhost). and the user is just passed as a Signer through the account.
    – ZeroNine
    Jan 29 at 3:10
  • Nevermind, I had to read your answer a few times.. I understand now. Thank you for this.. It took me a while for it to sink in.
    – ZeroNine
    Jan 29 at 3:18
  • Sweet! You're welcome
    – Ademola
    Jan 30 at 6:40

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.