2

I'm trying to parse the raw transaction of this transaction on mainnet: 0x2cd10c5a49963ea7009be96fd4651e4009c719f680096cd8c66c083b48ba5de6.

The hex encoding of the raw signed transaction is

0xb9019602f9019201428459682f00850dba9fbbf48303793c947a250d5630b4cf539739df2c5dacb4c659f2488d80b9012438ed1739000000000000000000000000000000000000000000000000000000012a16030000000000000000000000000000000000000000000000000000000004ddd75eac00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000018c393f77835b9f37ad8500bcbf739bff9f82ce0000000000000000000000000000000000000000000000000000000061b7209200000000000000000000000000000000000000000000000000000000000000030000000000000000000000002b89bf8ba858cd2fcee1fada378d5cd6936968be000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48c001a0c57a8fc131811dce50bbd061ff1f24a6f32a067ce629a51ca3c08287479aac9ea01521d308b35ce9710a19a52f8eaeff43f9b75d2b0f45f515de6a3b5d0c6d6f06

When decoding with ethers, this results in the following error:

const ethers = require('ethers')

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

main()

Output: Error: invalid raw transaction.

What needs to be fixed to parse this transaction?

4 Answers 4

1

You need to pass an object to .parseTransaction:

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

parseTransaction works on a serialized ethers transaction.

I think what you're looking for might be getTransaction which receives the tx hash and returns the tx info. Documentation

0

You need the ABI of that contract, then you'll be able to decode it.

Using abi-decoder library, place the whole ABI in abi.js as module.exports=[...ABI...] -

    const abiDecoder = require('abi-decoder');
    abiDecoder.addABI(require('./abi'));
    const data = '0x38ed1739000000000000000000000000000000000000000000000000000000012a16030000000000000000000000000000000000000000000000000000000004ddd75eac00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000018c393f77835b9f37ad8500bcbf739bff9f82ce0000000000000000000000000000000000000000000000000000000061b7209200000000000000000000000000000000000000000000000000000000000000030000000000000000000000002b89bf8ba858cd2fcee1fada378d5cd6936968be000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48';
    const decodedData = abiDecoder.decodeMethod(data);
    console.log(JSON.stringify(decodedData));

result -

{"name":"swapExactTokensForTokens","params":[{"name":"amountIn","value":"5001052928","type":"uint256"},{"name":"amountOutMin","value":"20901748396","type":"uint256"},{"name":"path","value":["0x2b89bf8ba858cd2fcee1fada378d5cd6936968be","0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"],"type":"address[]"},{"name":"to","value":"0x018c393f77835b9f37ad8500bcbf739bff9f82ce","type":"address"},{"name":"deadline","value":"1639391378","type":"uint256"}]}
0

The provided raw tx hex is not valid. You can check here: https://rawtxdecode.in/

The valid raw tx hex for this tx is:

0x02f9019201428459682f00850dba9fbbf48303793c947a250d5630b4cf539739df2c5dacb4c659f2488d80b9012438ed1739000000000000000000000000000000000000000000000000000000012a16030000000000000000000000000000000000000000000000000000000004ddd75eac00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000018c393f77835b9f37ad8500bcbf739bff9f82ce0000000000000000000000000000000000000000000000000000000061b7209200000000000000000000000000000000000000000000000000000000000000030000000000000000000000002b89bf8ba858cd2fcee1fada378d5cd6936968be000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48c001a0c57a8fc131811dce50bbd061ff1f24a6f32a067ce629a51ca3c08287479aac9ea01521d308b35ce9710a19a52f8eaeff43f9b75d2b0f45f515de6a3b5d0c6d6f06

Here is the decoded response for valid tx hex

{
  "chainId": "1",
  "type": "EIP-1559",
  "valid": true,
  "hash": "0x2cd10c5a49963ea7009be96fd4651e4009c719f680096cd8c66c083b48ba5de6",
  "nonce": "66",
  "gasLimit": "227644",
  "maxFeePerGas": "58965605364",
  "maxPriorityFeePerGas": "1500000000",
  "from": "0x018C393F77835b9f37aD8500bCBF739Bff9F82CE",
  "to": "0x7a250d5630b4cf539739df2c5dacb4c659f2488d",
  "publicKey": "0x0409182ae303dc6bf92ffaa49834c59aa19f2bfb4af63be839771cbd6b398cff8c085af0050ad8205778d33204e7640da16afcfb28bbff9bae0f741bcedc713fd5",
  "v": "01",
  "r": "c57a8fc131811dce50bbd061ff1f24a6f32a067ce629a51ca3c08287479aac9e",
  "s": "1521d308b35ce9710a19a52f8eaeff43f9b75d2b0f45f515de6a3b5d0c6d6f06",
  "value": "0",
  "data": "0x38ed1739000000000000000000000000000000000000000000000000000000012a16030000000000000000000000000000000000000000000000000000000004ddd75eac00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000018c393f77835b9f37ad8500bcbf739bff9f82ce0000000000000000000000000000000000000000000000000000000061b7209200000000000000000000000000000000000000000000000000000000000000030000000000000000000000002b89bf8ba858cd2fcee1fada378d5cd6936968be000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
  "functionHash": "0x38ed1739",
  "possibleFunctions": [
    {
      "definition": "swapExactTokensForTokens(uint256,uint256,address[],address,uint256)",
      "decodedInputs": [
        "5001052928",
        "20901748396",
        [
          "0x2B89bF8ba858cd2FCee1faDa378D5cd6936968Be",
          "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
          "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
        ],
        "0x018C393F77835b9f37aD8500bCBF739Bff9F82CE",
        "1639391378"
      ]
    }
  ]
}
1
  • 1
    Your answer could be improved by indicating how/where you found the correct hex string. Commented Aug 23, 2023 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.