This article explains how to make a copy of a transaction from a parsed transaction in Solana:
Making a Copy of a Transaction in Solana Using Web3.js
When working with transactions on the Solana blockchain, it is not uncommon to find yourself needing to replicate or duplicate certain transactions. While parsing a transaction can provide valuable insights into the data, it may not always give you direct access to the account key indexes used by the transaction. In this article, we will explore how to make a copy of a transaction in Solana using Web3.js.
Why is it necessary?

In some cases, you may need to:
- Recreate a specific transaction for testing or development
- Use another user’s account keys in a test scenario
- Create a backup of the transaction to prevent data loss
How to Make a Copy of a Parsed Transaction in Solana
To make a copy of a parsed transaction, you need to use the Transaction.copy() method. This method creates a new transaction with the same accounts and key indexes as the original transaction.
const parsedTransaction = await transaction.parse();
const copiedTransaction = await Transaction.copy(parsedTransaction);
However, if you are still having problems with account key indexes exceeding staticAccountKeys, you can try the Transaction.fromStaticAccounts() method. This will create a new transaction with only the specified accounts and their corresponding key indexes.
const parsedTransaction = await transaction.parse();
const copiedTransaction = Transaction.fromStaticAccounts(parsedTransaction.staticAccounts);
Example Use Case: Recreating a Transaction for Testing
Suppose you have a specific transaction that involves transferring 10 SOLs from account «0x1234567890abcdef» to account «0x9876543210fedcba». You want to recreate this transaction in your development environment, but you only have access to the parsed transaction and no direct access to the static accounts.
const parsedTransaction = await transaction.parse();
const copiedTransaction = Transaction.fromStaticAccounts(parsedTransaction.staticAccounts);
// Use the copied transaction for testing or development purposes as needed.
Conclusion
In this article, we have explored how to make a copy of a parsed transaction in Solana using Web3.js. By understanding when you need to use Transaction.copy() and when you can use Transaction.fromStaticAccounts(), you can safely replicate specific transactions in your development environment.
Remember that account key indexes are dynamic, meaning they change over time based on user activity. Be sure to test all new transactions in a controlled environment before deploying them to production.
I hope this helps! Let me know if you have any questions or need further assistance.
