0

I want to find and initialize a PDA for Token Swap Program https://spl.solana.com/token-swap

It keeps throwing this error:

     transactionMessage: 'Transaction simulation failed: Error processing Instruction 0: custom program error: 0xe',
  transactionLogs: [
    'Program SwapsVeCiPHMUAtzQWZw7RjsKjgCjhwU55QGu4U1Szw invoke [1]',
    'Program log: Error: InvalidInstruction',
    'Program SwapsVeCiPHMUAtzQWZw7RjsKjgCjhwU55QGu4U1Szw consumed 1071 of 200000 compute units',
    'Program SwapsVeCiPHMUAtzQWZw7RjsKjgCjhwU55QGu4U1Szw failed: custom program error: 0xe'
  ]

Here is my code, I was following the tutorial at https://solanacookbook.com/references/accounts.html#create-a-pda

  const masterPayerPubKey = masterPayerKeypair.publicKey;
  const programId = splTokenSwap.TOKEN_SWAP_PROGRAM_ID;

  let [pdaPubKey, bumpSeed] = await solanaWeb3.PublicKey.findProgramAddress(
    [masterPayerPubKey.toBuffer()], 
    programId,
  );

  let connection = new solanaWeb3.Connection(solanaWeb3.clusterApiUrl("devnet"), "confirmed");

  // Transaction Instruction for initializing PDA (Program Derived Address)
  // https://solanacookbook.com/references/accounts.html#create-a-pda
  const data_size = 0;
  let initializePDATx = new solanaWeb3.Transaction().add(
    new solanaWeb3.TransactionInstruction({
      keys: [
        {
          pubkey: masterPayerPubKey,
          isSigner: true,
          isWritable: true,
        },
        {
          pubkey: pdaPubKey,
          isSigner: false,
          isWritable: true,
        },
        {
          pubkey: solanaWeb3.SYSVAR_RENT_PUBKEY,
          isSigner: false,
          isWritable: false,
        },
        {
          pubkey: solanaWeb3.SystemProgram.programId,
          isSigner: false,
          isWritable: false,
        },
      ],
      data: Buffer.from(new Uint8Array([data_size, bumpSeed])), 
      programId: programId
    })
  );

  let transactionHash = await connection.sendTransaction(initializePDATx, [masterPayerKeypair]);
  await connection.confirmTransaction(transactionHash);

1 Answer 1

2

0xe is 14 in base 10 notation. Going through the token swap program errors, you see that this matches the invalid instruction error.

There isn't an initialize PDA ix and that might be the reason you are facing the error.

creating a PDA inside a program link -> https://solana.com/developers/cookbook/accounts/create-pda-account

also, confirmTransaction RPC is being deprecated and removed. Check out the transition guide in this link https://github.com/anza-xyz/agave/wiki/Agave-Transition

4
  • I don't believe you can use createAccount to initialize a PDA, since you don't have the secret key for a PDA to sign a createAccount transaction. If you have experience with this, do you mind sharing a code example?
    – Joseph Wu
    Commented Sep 13 at 14:28
  • 1
    you are correct. For a PDA you need to do it inside the program if the account isn't initialized so that you can sign using the PDA seeds.
    – Jimii
    Commented Sep 13 at 15:43
  • I'm sorry but this isn't very helpful. I already referenced the Solana Cookbook link. That's the example I followed. If you have experience with initializing PDA via JS and have run into the same problem, please let me know where my code is wrong. I've read that documentation about 100 times by this point.
    – Joseph Wu
    Commented Sep 13 at 16:42
  • I am saying that you cannot create a PDA outside the program. it's impossible. You need to have an ix inside the program that creates or initializes the PDA for you.
    – Jimii
    Commented Sep 19 at 16:06

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.