Search code examples
solanametaplex

Metaplex Auction House Error "Error processing Instruction 0: insufficient account keys for instruction"


I have been trying to run the execute_sale ix from the mpl-auction-house package but I get this error in the logs I have got the sellInstruction and buyInstruction working enter image description here

This is my Code

  const executeSellInstructionAccounts:ExecuteSaleInstructionAccounts = {
    buyer:buyerwallet.publicKey,
    seller:Sellerwallet.publicKey,
    tokenAccount:tokenAccountKey,
    tokenMint:mint,
    metadata:await getMetadata(mint),
    treasuryMint:new anchor.web3.PublicKey(AuctionHouse.mint),
    auctionHouse:new anchor.web3.PublicKey(AuctionHouse.address),
    auctionHouseFeeAccount:new anchor.web3.PublicKey(AuctionHouse.feeAccount),
    authority:new anchor.web3.PublicKey(AuctionHouse.authority),
    programAsSigner:programAsSigner,
    auctionHouseTreasury:new anchor.web3.PublicKey(AuctionHouse.treasuryAccount),
    buyerReceiptTokenAccount:buyerATA.address,
    sellerPaymentReceiptAccount:Sellerwallet.publicKey,
    buyerTradeState:BuyertradeState,
    escrowPaymentAccount:escrowPaymentAccount,
    freeTradeState:freeTradeState,
    sellerTradeState:SellertradeState,
  }

  const executeSellInstructionArgs:ExecuteSaleInstructionArgs = {
      escrowPaymentBump:escrowBump,
      freeTradeStateBump:freeTradeBump,
      programAsSignerBump:programAsSignerBump,
      buyerPrice:buyPriceAdjusted,
      tokenSize:tokenSizeAdjusted,
  }


  const execute_sale_ix = createExecuteSaleInstruction(
    executeSellInstructionAccounts,executeSellInstructionArgs
  )

  const execute_sale_tx = new anchor.web3.Transaction(
    {
      recentBlockhash: blockhash,
      feePayer: Sellerwallet.publicKey,
    }
  )

  execute_sale_tx.add(execute_sale_ix);

  const execute_sale_res = await sprovider.sendAndConfirm(execute_sale_tx);

Solution

  • There is currently a discrepancy between the published AuctionHouse SDK and the underlying Rust program.

    The console reference implementation is here: https://github.com/metaplex-foundation/metaplex/blob/master/js/packages/cli/src/auction-house-cli.ts

    The console reference implementation works because it loads the idl directly from the chain and is therefore up to date. It bypasses the AuctionHouse SDK completely.

    However, if you're doing this in the browser, you probably don't want to load the IDL from the chain. You'd need things like a decompression library and that would blow up your package size quite a bit.

    To work around this, I've forked metaplex repo here: https://github.com/neftworld/metaplex

    The fork above has the following changes:

    1. Including the IDL definition as a typescript src file (correct as at 30 May 2022)
    2. Fetching auctionHouse program from local IDL definition instead getting it from the chain

    Hence, you can use this as a base for your web implementation. To make this work on the web, you will need to remove references to keypair - console uses a key pair file - and use the browser wallet to sign the transaction before sending.