You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解码Solana交易?基于Solana web3 JS库的交易解码问题咨询

Solana序列化原始交易解码方案

solana-web3.js内置了完整的交易解码能力,你可以根据你使用的库版本选择对应方法:

  • v1.x版本web3.js
    • 解析传统legacy交易,直接调用Transaction.from()静态方法,传入序列化后的Uint8Array/Buffer格式交易数据即可:
      import { Transaction } from '@solana/web3.js';
      // serializedTx为你持有的序列化原始交易数据
      const decodedTransaction = Transaction.from(serializedTx);
      // 可直接读取feePayer、signatures、instructions、recentBlockhash等交易字段
      
    • 解析v0版本化交易,调用VersionedTransaction.deserialize()方法:
      import { VersionedTransaction } from '@solana/web3.js';
      const decodedVersionedTx = VersionedTransaction.deserialize(serializedTx);
      
  • v2.x版本web3.js
    对应解码方法为decodeTransaction(),导入后直接传入序列化交易即可:
    import { decodeTransaction } from '@solana/web3.js/transaction';
    const decodedTx = decodeTransaction(serializedTx);
    

如果你需要进一步解析交易内的具体指令内容,需要结合对应程序的ID使用对应程序的解析工具,比如系统指令、SPL系列程序指令都有单独的解析方法可以调用。

内容的提问来源于stack exchange,提问作者f4r4

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 01:36:01