2

I have a anchor program locally that runs perfectly with anchor typescript client, but while trying to access with rust's solana_client it throws this error:

AnchorError caused by account: system_program. Error Code: InvalidProgramId. Error Number: 3008. Error Message: Program ID was not as expected.

I have defined the same program id with:

let program_id = Pubkey::from_str("my_program_id").unwrap();

The weirdest part is that it even finds the correct instruction, so I'm completely clueless about this error message.

This is how I'm trying to call the instruction:

let instruction = Instruction::new_with_bytes(
    program_id,
    _r, // my instruction
    vec![
        AccountMeta::new(my_account.pubkey(), false),
        AccountMeta::new(payer.pubkey(), true),
        AccountMeta::new(program_id, false),
    ],
);

1 Answer 1

3

As silly as it sounds, the last account should be a solana system program id, and not my program id. This was the fix:

let solana_program_id = solana_sdk::system_program::id();

let instruction = Instruction::new_with_bytes(
    program_id,
    instruction,
    vec![
        AccountMeta::new(my_account.pubkey(), true),
        AccountMeta::new(payer.pubkey(), false),
        AccountMeta::new(solana_program_id, false),
    ],
);
1
  • Yeah looks like to create a new account your program needs the system program.
    – Jonas H.
    Nov 17, 2022 at 8:08

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.