title: Solana: Create PDA account on chain
body: <p>I am trying to write a Solana program which creates a PDA account for me on-chain. I can't get it to work and tbh, no idea what I am doing wrong :/</p>
  <p>I have the following code in my Solana program:</p>
  <pre class="lang-rust prettyprint-override"><code>        let account_info_iter = &amp;mut accounts.iter();
          let initializer = next_account_info(account_info_iter)?;
  
          if !initializer.is_signer {
              return Err(ProgramError::MissingRequiredSignature);
          }
  
          let (pda, bump_seed) = Pubkey::find_program_address(&amp;[b&quot;admin_account&quot;], program_id);
          let admin_account = next_account_info(account_info_iter)?;
  
          
          if admin_account.key != &amp;pda {
              return Err(CustomError::InvalidAdminAccount.into());
          }
  
          // we are checking if the account is rent exempt. In case it is, the account is already initialized
          if **admin_account.try_borrow_lamports()? &gt; 0 {
              msg!(&quot;This account is already initialised. skipping&quot;);
              return Ok(())
          }
  
          let lamports = Rent::default().minimum_balance(1);
  
          let ix = solana_program::system_instruction::create_account(
              initializer.key,
              admin_account.key,
              lamports,
              1,
              program_id,
          );
  
          // Sign and submit transaction
          invoke_signed(
              &amp;ix,
              &amp;[initializer.clone(), admin_account.clone()],
              &amp;[&amp;[b&quot;admin_account&quot;], &amp;[&amp;[bump_seed]]]
          )?;
  </code></pre>
  <p>And here my Python script:</p>
  <pre><code>
      pda_account, nonce = PublicKey.find_program_address([b&quot;admin_account&quot;], PROGRAM_ID)
      
      init_ix = TransactionInstruction(
          data=bytes(1),
          keys=[
              AccountMeta(pubkey=ADMIN_KEYPAIR.public_key, is_signer=True, is_writable=False),
              AccountMeta(pubkey=pda_account, is_signer=False, is_writable=True),
          ],
          program_id=PROGRAM_ID,
      )
  
      transaction = Transaction()
      transaction.add(init_pantos_token_ix)
  
      utils.send_and_confirm_tx(CLIENT, transaction, ADMIN_KEYPAIR)
  </code></pre>
  <p>Whenever I execute the transaction I get the following error message:</p>
  <pre><code>Transaction simulation failed: Error processing Instruction 0: An account required by the instruction is missing
  </code></pre>
  <p>But what account is missing? I tried with the System Program but that gives me another error :/
  Anyone any ideas?</p>