2

I'm working with Raydium and Jupiter swap APIs, which return serialized transactions that need to be deserialized before sending. In the older version of @solana/web3.js, this was done using VersionedTransaction.deserialize() or Transaction.from().

With @solana/web3.js v2, these methods no longer exist. Here's an example of what I'm trying to convert:

// Old code
const allTxBuf = swapTransactions.data.map((tx) => Buffer.from(tx.transaction, 'base64'))
const allTransactions = allTxBuf.map((txBuf) =>
  isV0Tx ? VersionedTransaction.deserialize(txBuf) : Transaction.from(txBuf)
)

The transactions come from API endpoints like Raydium's swap endpoint:

const { data: swapTransactions } = await axios.post<{
  data: { transaction: string }[]
}>('/transaction/swap-base-in', {
  // ... swap parameters
})

What's the equivalent way to deserialize these transactions using the new version of @solana/web3.js?

1 Answer 1

1

Okay, i found it. In v2, you need to use transaction decoders to deserialize transactions. Here's how:

  1. First, get a transaction decoder:
const transactionDecoder = getTransactionDecoder();
  1. Then use it to decode the transaction buffer:
const decodedTx = transactionDecoder.decode(txBuf);

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.