Ethers.js

乙太幣無法解析原始交易

  • March 23, 2022

我正在嘗試在主網上解析此交易的原始交易:0x2cd10c5a49963ea7009be96fd4651e4009c719f680096cd8c66c083b48ba5de6

原始簽名交易的十六進制編碼是

0xb9019602f9019201428459682f00850dba9fbbf48303793c947a250d5630b4cf539739df2c5dacb4c659f2488d80b9012438ed1739000000000000000000000000000000000000000000000000000000012a16030000000000000000000000000000000000000000000000000000000004ddd75eac00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000018c393f77835b9f37ad8500bcbf739bff9f82ce0000000000000000000000000000000000000000000000000000000061b7209200000000000000000000000000000000000000000000000000000000000000030000000000000000000000002b89bf8ba858cd2fcee1fada378d5cd6936968be000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48c001a0c57a8fc131811dce50bbd061ff1f24a6f32a067ce629a51ca3c08287479aac9ea01521d308b35ce9710a19a52f8eaeff43f9b75d2b0f45f515de6a3b5d0c6d6f06

使用 解碼時ethers,會導致以下錯誤:

const ethers = require('ethers')

function main() {
   const raw = '0xb9019602f9019201428459682f00850dba9fbbf48303793c947a250d5630b4cf539739df2c5dacb4c659f2488d80b9012438ed1739000000000000000000000000000000000000000000000000000000012a16030000000000000000000000000000000000000000000000000000000004ddd75eac00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000018c393f77835b9f37ad8500bcbf739bff9f82ce0000000000000000000000000000000000000000000000000000000061b7209200000000000000000000000000000000000000000000000000000000000000030000000000000000000000002b89bf8ba858cd2fcee1fada378d5cd6936968be000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48c001a0c57a8fc131811dce50bbd061ff1f24a6f32a067ce629a51ca3c08287479aac9ea01521d308b35ce9710a19a52f8eaeff43f9b75d2b0f45f515de6a3b5d0c6d6f06'
   const tx = ethers.utils.parseTransaction(raw)
   console.log(tx)
}

main()

輸出Error: invalid raw transaction

解析此交易需要解決什麼問題?

parseTransaction處理序列化的乙太交易。

我認為您正在尋找的可能是getTransaction接收 tx 雜湊並返回 tx 資訊。文件

您需要將對像傳遞給.parseTransaction

const raw = '0xb9019602f9019201428459682f00850dba9fbbf48303793c947a250d5630b4cf539739df2c5dacb4c659f2488d80b9012438ed173900000...'
const tx = ethers.utils.parseTransaction({ data: raw })

引用自:https://ethereum.stackexchange.com/questions/115490