Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

send transaction for versioned transaction error type #108

Open
ParzifaL-03 opened this issue Oct 31, 2024 · 0 comments
Open

send transaction for versioned transaction error type #108

ParzifaL-03 opened this issue Oct 31, 2024 · 0 comments

Comments

@ParzifaL-03
Copy link

StructError: Expected the value to satisfy a union of type | type, but received: [object Object]

const swapTransaction = await Liquidity.makeSwapInstructionSimple({
      connection: connection,
      makeTxVersion: useVersionedTransaction ? 0 : 1,
      poolKeys: {
        ...poolKeys,
      },
      userKeys: {
        tokenAccounts: userTokenAccounts,
        owner: this.wallet.publicKey,
      },
      amountIn: amountIn,
      amountOut: minAmountOut,
      fixedSide: fixedSide,
      config: {
        bypassAssociatedCheck: false,
      },
      computeBudgetConfig: {
        microLamports: maxLamports,
      },
    });
const recentBlockhashForSwap = await connection.getLatestBlockhash();
    const instructions =
      swapTransaction.innerTransactions[0].instructions.filter(Boolean);

      const versionedTransaction = new VersionedTransaction(
        new TransactionMessage({
          payerKey: this.wallet.publicKey,
          recentBlockhash: recentBlockhashForSwap.blockhash,
          instructions: instructions,
        }).compileToV0Message()
      );

      const serialized = toBuffer(versionedTransaction.serialize());
      console.log("simulate tx string:", serialized.toString("base64"));

      versionedTransaction.sign([this.wallet]);

      return versionedTransaction;
async sendVersionedTransaction(tx: VersionedTransaction, maxRetries: number) {
    const txid = await connection.sendTransaction(tx, {
      skipPreflight: true,
      maxRetries: maxRetries,
    });

    return txid;
  }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant