Loading video player...
Learn how to decode Solana transaction instruction data encoded in Base58 using Python, extracting instruction types and amounts for analysis. --- This video is based on the question https://stackoverflow.com/q/79460187/ asked by the user 'Qeyzho' ( https://stackoverflow.com/u/21508170/ ) and on the answer https://stackoverflow.com/a/79460548/ provided by the user 'htrehrthtr' ( https://stackoverflow.com/u/22177345/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions. Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Data decoding in Solana transaction Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/licensing The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/by-sa/4.0/ ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/by-sa/4.0/ ) license. If anything seems off to you, please feel free to drop me a comment under this video. --- Understanding and Decoding Solana Transaction Instruction Data The Problem When analyzing Solana transactions in Python, the instruction data often comes as a Base58-encoded string inside JSON. Decoding this data is essential to understand what the transaction does—for example, identifying a token transfer and the amount involved. Consider this transaction snippet: [[See Video to Reveal this Text or Code Snippet]] The string under the data key represents encoded instruction details, but it isn't immediately clear how to decode it. Solution Overview Solana encodes instruction data as a Base58 string. For the standard System Program transfer instruction, the layout is: Byte 0: Instruction index (usually 2 for transfer) Bytes 1-8: Amount in lamports, encoded as a little-endian unsigned 64-bit integer To decode: Decode the Base58 string to bytes. Extract the instruction type from the first byte. Parse the next 8 bytes as a little-endian integer representing lamports. Python Code Example [[See Video to Reveal this Text or Code Snippet]] Key Points Base58 is the standard encoding for encoding instruction data in Solana transactions. The transfer instruction index is often 2, but consult Solana docs or programs for other instructions. Amounts are represented in lamports (1 SOL = 1,000,000,000 lamports). By decoding the transaction data this way, you can programmatically analyze what Solana transactions do and extract meaningful amounts.