1

I have an IDL here and I am trying to convert a function, but it is giving me errors. I am trying to use it on the browser. Can you please help as this is urgent? Thanks.

IDL:

    {
  "name": "initPurchase",
  "accounts": [
    {
      "name": "buyer",
      "isMut": true,
      "isSigner": true
    },
    {
      "name": "item",
      "isMut": true,
      "isSigner": false
    },
    {
      "name": "merchant",
      "isMut": false,
      "isSigner": false
    },
    {
      "name": "transaction",
      "isMut": true,
      "isSigner": false
    },
    {
      "name": "vault",
      "isMut": true,
      "isSigner": false
    },
    {
      "name": "buyerWallet",
      "isMut": true,
      "isSigner": false
    },
    {
      "name": "mint",
      "isMut": false,
      "isSigner": false
    },
    {
      "name": "tokenProgram",
      "isMut": false,
      "isSigner": false
    },
    {
      "name": "systemProgram",
      "isMut": false,
      "isSigner": false
    },
    {
      "name": "rent",
      "isMut": false,
      "isSigner": false
    }
  ],
  "args": [
    {
      "name": "amount",
      "type": "u64"
    }
  ]
},

My code:

const purchaseInitiation = await this.program.methods
  .initPurchase(itemAmountBN)
  .accounts({
    //@ts-ignore
    buyer: this.userPubKey,
    item: itemPDA,
    merchant: merchantPDA,
    transaction: transactionPDA,
    vault: vaultPDA,
    //@ts-ignore
    buyerWallet: this.userPubKey,
    mint: itemCurrencyMintAddress,
  })
  .transaction();

const transactionSignature =
  await this.sendAndConfirmTransactionWithAnchorWallet(purchaseInitiation);

Is there anything I am missing, because I keep getting this error:

index.browser.esm.js?156f:7826 Uncaught (in promise) Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0xbbf
at Connection.sendEncodedTransaction (index.browser.esm.js?156f:7826:1)
at async Connection.sendRawTransaction (index.browser.esm.js?156f:7783:1)

Any help would be greatly appreciated. Thanks.

2 Answers 2

3

The error you got is indicating that one of the accounts provided to the instruction is owned by a different program than the one handling it.

This is most likely a seeding issue for one or more of the PDAs. Check to make sure that:

  1. The program was deployed to the current address with the correct declare_id value
  2. The program ID used in the PDA derivation function calls matches that.
0

When you run anchor build, there's a TS version of the IDL in the target folder

However, the error you are getting is:

#[msg("The given account is owned by a different program than expected")]

https://github.com/coral-xyz/anchor/blob/master/lang/src/error.rs#L154

enter image description here

1
  • Hey, thanks for your response. Though I'm not sure what I should be doing to fix the problem. There are some inputs that I missed but I'm not sure if they matter.
    – incog
    Commented Aug 19, 2022 at 20:36

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.