-1

i'm thinking the client can't create my pda state_account since only the program can sign for it, but i must be missing something. my native excerpt:

        let state_account = next_account_info(account_info_iter)?;
        let rent = Rent::default().minimum_balance(State::LEN);

        let seeds = [ "state_".as_bytes(), &[seed_bump] ];
        let signers = &[&seeds[..]];
        let create_ix = create_account(
            payer.key,
            state_account.key,
            rent,
            State::LEN as u64,
            my_program_id
        );
        invoke_signed(&create_ix, &[
                payer.clone(),
                state_account.clone()
            ], signers)?;

1 Answer 1

1

had a type-o in my client. never the less the restated code looks a little better, and the state_account does get created

        let account_info_iter = &mut accounts.iter();
        let payer = next_account_info(account_info_iter)?;
        let state_account = next_account_info(account_info_iter)?;
        let system_program = next_account_info(account_info_iter)?;

        assert!(payer.is_signer);
        assert!(payer.is_writable);
        assert!(state_account.is_writable);
        assert_eq!(state_account.owner, &system_program::ID);
        assert!(system_program::check_id(system_program.key));

        let seeds = &["state_".as_bytes(), &[seed_bump]];
        let expected_state_account = Pubkey::create_program_address(
            seeds, program_id)?;
        assert_eq!(state_account.key, &expected_state_account);

        let rent = Rent::default().minimum_balance(State::LEN);
        invoke_signed(
            &system_instruction::create_account(
                &payer.key,
                &state_account.key,
                rent,
                State::LEN as u64,
                &program_id,
            ),
            &[ payer.clone(), state_account.clone(), ],
            &[ &["state_".as_bytes(), &[seed_bump]] ],
        )?;
        Ok(())

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