-
Notifications
You must be signed in to change notification settings - Fork 110
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Motivation
If you want to fetch a transaction from the RPC by signature today you might do something like this:
const result = await rpc
.getTransaction(
signature(
"265Vry9E7VMD92AX79R1A5zaBmyYAMVarZq4YTWCrCnhzBtEAFaHYrbWHmdi5wvJoWGdeH9jKvAgMLVncQUBGEK1"
),
{ encoding: "base64" }
)
.send();
if (!result) {
throw Error("Transaction not found");
}
const {
transaction: [wireTransaction],
} = result;
const transferCheckedInstruction = pipe(
wireTransaction,
// Decode the wire transaction.
getBase64Encoder().encode,
getTransactionDecoder().decode,
// Decode the message.
(transaction) =>
getCompiledTransactionMessageDecoder().decode(transaction.messageBytes),
decompileTransactionMessage
);
That's probably enough boilerplate to extract into a helper.
Example use case
const transaction = await fetchDecompiledTransaction(
rpc,
signature('265Vry9E7VMD92AX79R1A5zaBmyYAMVarZq4YTWCrCnhzBtEAFaHYrbWHmdi5wvJoWGdeH9jKvAgMLVncQUBGEK1'),
);
for (const instruction in transaction.instructions) {
// ...
}
Details
Implement this in @solana/transactions
as fetchDecompiledTransaction(rpc: Rpc<GetTransactionApi>, signature: Signature)
.
metasal1, mcintyre94 and lorisleiva
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request