+
Skip to content

A function to fetch a decompiled Transaction by signature #275

@steveluscher

Description

@steveluscher

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载