当前位置:网站首页>BSC parsing input data of transaction

BSC parsing input data of transaction

2022-06-25 03:54:00 Blockchain research

Take this as an example :https://bscscan.com/tx/0x46ab3eda9ca611bbb839bab26b67425f38d577ede8fb350cc3b30b5431483acf

 Insert picture description here
See this line of small letters ? Click in , There is a library dedicated to parsing .

analysis input To get rid of At the beginning 10 Characters , Because that is the encrypted character of the method .

The complete code is as follows :

let input_data = `0x7ff36ab500000000000000000000000000000000000000000073ef44020e785db242c9dd000000000000000000000000000000000000000000000000000000000000008000000000000000000000000060675dbb66f2c58b5ab07cdc7b034b95c59289090000000000000000000000000000000000000000000000000000000061e1cd290000000000000000000000000000000000000000000000000000000000000002000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c0000000000000000000000007fb4ed1b35d8f8638056913bece78b8cd624ca0d`;

input_data = input_data.substring(10);


const {
    decodeConstructorArgs} = require('canoe-solidity');
let abiExample = {
    
    'abi': [
        {
    
            "inputs": [
                {
    "internalType": "uint256", "name": "amountOutMin", "type": "uint256"},
                {
    
                    "internalType": "address[]",
                    "name": "path",
                    "type": "address[]"
                }, {
    "internalType": "address", "name": "to", "type": "address"},
                {
    
                    "internalType": "uint256",
                    "name": "deadline",
                    "type": "uint256"
                }
            ],
            'type': 'constructor'
        }
    ]
};

console.log(decodeConstructorArgs(abiExample.abi, input_data));

Output :

[
  {
    
    name: 'amountOutMin',
    type: 'uint256',
    data: '140156369371873394114611677'
  },
  {
    
    name: 'path',
    type: 'address[]',
    data: [
      'bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c',
      '7fb4ed1b35d8f8638056913bece78b8cd624ca0d'
    ]
  },
  {
    
    name: 'to',
    type: 'address',
    data: '60675dbb66f2c58b5ab07cdc7b034b95c5928909'
  },
  {
     name: 'deadline', type: 'uint256', data: '1642188073' }
]
原网站

版权声明
本文为[Blockchain research]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210537010245.html