Is there a JS API to recover fromPubkey and toPubkey, given a transaction signature?
1 Answers
If you have a transaction signature, you can fetch the transaction using the JSON RPC API's getTransaction
endpoint: https://docs.solana.com/developing/clients/jsonrpc-api#gettransaction
This endpoint allows you to ask for jsonParsed
encoding, which will actually decode everything for you. Note that not all transactions support JSON parsing.
EDIT: The below is only applicable for encoded transactions, and is not required for system instructions that contain a parser already.
Assuming the encoded transaction actually contains a transfer instruction to the system program, there's a decodeTransfer
helper to do this: https://github.com/solana-labs/solana/blob/005592998dd107b3d54d9203babe24da681834f5/web3.js/src/system-program.ts#L266
For other transfers, you'll have to write your own decoder in JS. The Rust side has all of these defined already for you in the solana-transaction-status
crate: https://github.com/solana-labs/solana/blob/master/transaction-status/src/parse_instruction.rs

- 7,019
- 10
- 17
-
Thanks Jon! Yes, it is a transfer instruction to the system program. Could you help me with an example of how this must be used? All I have is a string corresponding to a transactionSignature. – Manish Sharma Jan 06 '22 at 16:12
-
Ah I'm sorry, I missed the part asking about the signature -- editing my original answer... – Jon C Jan 06 '22 at 17:43
-
How to use decodeTransfer – Javin Yang Nov 01 '22 at 13:50