jup-ag / jupiter-quote-api-node

91 stars 32 forks source link

Instruction Error 3012 #22

Open Moustafa22 opened 7 months ago

Moustafa22 commented 7 months ago

Hi,

I applied the same code in the documentation everything seems fine, except when the transaction is executed.

qoute code

 const quoteResponse = await (
      await fetch(
        `https://quote-api.jup.ag/v6/quote?inputMint=${fromContract}&outputMint=${toContract}&amount=${amount}&slippageBps=50&onlyDirectRoutes=false&platformFeeBps=100`, // 1%
      )
    ).json();

swap transaction code


    const { swapTransaction } = await (
      await fetch('https://quote-api.jup.ag/v6/swap', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          // quoteResponse from /quote api
          quoteResponse,
          // user public key to be used for the swap
          userPublicKey: wallet.publicKey.toString(),
          // auto wrap and unwrap SOL. default is true
          wrapAndUnwrapSol: true,
          // feeAccount is optional. Use if you want to charge a fee.  feeBps must have been passed in /quote API.
          feeAccount: 'MY_WALLET_ADDRESS',
          dynamicComputeUnitLimit: true,

          prioritizationFeeLamports: 'auto', // or custom lamports: 1000
        }),
      })
    ).json();

sign code


    const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');
    var transaction = VersionedTransaction.deserialize(swapTransactionBuf);

    // sign the transaction
    transaction.sign([wallet.payer]);

    const rawTransaction = transaction.serialize();
    const txid = await this.connection.sendRawTransaction(rawTransaction, {
      skipPreflight: true,
      maxRetries: 2,
    });

    console.log(`https://solscan.io/tx/${txid}`);
    try {
      var resp = await this.connection.confirmTransaction(txid);
    } catch (e) {
      if (e instanceof TransactionExpiredTimeoutError) {
        console.log('Timeout');
      }
    }
    console.log(resp.value.err);

i am getting this error { InstructionError: [ 2, { Custom: 3012 } ] } and this error code is not mentioned in the documentation

in solscan status : Program Error: "Instruction #3 Failed" program log

Program Jupiter Aggregator v6 consumed 9671 of 1400000 compute units Program returned error: custom program error: 0xbc4

I checked an exchange who uses jupiter APIs, use the same token pair and same amount, the request params and bodies were identical, but on the exchange the transactions are getting approved and on my platform the transactions are getting rejected with that error code.

Any Idea?