1

Before: There seemed to be a lack of solana nostd entrypoint documentation, I couldn't find any good resources.

I made solana program using solana_nostd_entrypoint. I want to create PDA account using InstructionC.

        let rent = solana_program::rent::Rent::default();
        let space = 1000;
        let rent_lamports = rent.minimum_balance(space);

        let mut instruction_data = [0u8; 56];
        instruction_data[4..12].copy_from_slice(&rent_lamports.to_le_bytes());
        instruction_data[12..20].copy_from_slice(&space.to_le_bytes());
        instruction_data[20..52].copy_from_slice(program_id.as_ref());
        let instruction_accounts = [signer.to_meta_c(), game_pda.to_meta_c()];

        let instruction = InstructionC {
            program_id: &system_program::ID,
            accounts: instruction_accounts.as_ptr(),
            accounts_len: instruction_accounts.len() as u64,
            data: instruction_data.as_ptr(),
            data_len: instruction_data.len() as u64,
        };
        let infos = [signer.to_info_c(), game_pda.to_info_c()];
        let seeds: &[&[&[u8]]] = &[&[GAME_PDA, &[GAME_PDA_BUMP]]];
        #[cfg(target_os = "solana")]
        unsafe {
            solana_program::syscalls::sol_invoke_signed_c(
                &instruction as *const InstructionC as *const u8,
                infos.as_ptr() as *const u8,
                infos.len() as u64,
                seeds.as_ptr() as *const u8,
                seeds.len() as u64,
            );
        }

But sol_invoke_signed_c fails because of lack of pda signature. Error log:

transactionLogs: [
    'Program ProgramID invoke [1]',
    'Program 11111111111111111111111111111111 invoke [2]',
    "Allocate: 'to' account Address { address: PDA account here, base: None } must sign",
    'Program 11111111111111111111111111111111 failed: missing required signature for instruction',
    'Program ProgramID  consumed 1555 of 200000 compute units',
    'Program ProgramID  failed: missing required signature for instruction'
  ]

Am I wrong to pass pda seeds and bump to sol_invoke_signed_c syscall cpi?

How can I fix this error?

1
  • I've tried several times. But couldn't find solution. This is urgent problem.
    – toygr
    Commented Nov 20 at 8:46

1 Answer 1

1

There's a specialized function for converting PDAs into an account meta usable for CPI: to_meta_c_signer https://github.com/cavemanloverboy/solana-nostd-entrypoint/blob/59856f0fd551845080482d64235914a0c4c7341a/solana-nostd-entrypoint/src/entrypoint_nostd.rs#L622

Try changing your code to:

        let instruction_accounts = [signer.to_meta_c(), game_pda.to_meta_c_signer()];
1
  • I also found that. Thanks.
    – toygr
    Commented Nov 23 at 16:23

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.