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?