2

I've got the following transaction's input:

{
    name: 'trade',
    types: [
        'address',
        'uint256',
        'address',
        'uint256',
        'uint256',
        'uint256',
        'address',
        'uint8',
        'bytes32',
        'bytes32',
        'uint256'
    ],
    inputs: ['ac709fcb44a43c35f0da4e3163b117a17f3770f5',
        <BN: 878678326eac900000>,
        '0000000000000000000000000000000000000000', 
        <BN: bf2aa18455018000>, 
        <BN: 302bdf>,
        <BN: dc51da3a>,
        'd8eeda4ee2657bb267bc35c1d60babdc5aedd269', 
        <BN: 1c>,
        <Buffer b4 bf 0 d cd 37 ca 73 bd 5 a bc e9 53 2 b 03 3 d cc 64 27 be 16 06 83 de 11 3e fc a4 13 20 c2 7 f 3e>, 
        <Buffer 78 79 9 d 84 04 0e 5 c 24 58 28 b1 b5 31 ef 97 e1 af 12 49 46 f4 dc 1 d b5 a2 0 c f2 8 a 70 73 b2 69>, 
        <BN: 275dcc081d0c2351e0>
    ]
}

This data came from raw transaction input which is

0x0a19b14a000000000000000000000000ac709fcb44a43c35f0da4e3163b117a17f3770f50000000000000000000000000000000000000000000000878678326eac9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000bf2aa184550180000000000000000000000000000000000000000000000000000000000000302bdf00000000000000000000000000000000000000000000000000000000dc51da3a000000000000000000000000d8eeda4ee2657bb267bc35c1d60babdc5aedd269000000000000000000000000000000000000000000000000000000000000001cb4bf0dcd37ca73bd5abce9532b033dcc6427be160683de113efca41320c27f3e78799d84040e5c245828b1b531ef97e1af124946f4dc1db5a20cf28a7073b2690000000000000000000000000000000000000000000000275dcc081d0c2351e0

How can I convert inputs to readable string values?

PS: by readable string values I mean converted values from BN and Buffer types to utf8 strings.

4
  • Can you explain where this data came from and what you're trying to get out? (What would "readable string values" look like?)
    – user19510
    Commented Feb 11, 2018 at 10:37
  • @smarx I've updated my question, hope this more makes sense now :)
    – Erik
    Commented Feb 11, 2018 at 10:45
  • 2
    I'm still not sure what you mean. Does .toString() on the BNs and .toString('hex') on the Buffers do what you want?
    – user19510
    Commented Feb 11, 2018 at 10:47
  • Let me check please
    – Erik
    Commented Feb 11, 2018 at 10:48

4 Answers 4

0

The tool ethereum-input-data-decoder, which you used to decode the encoded input data, returns uint types as Big Numbers and byte32 types as Buffers.

To convert to a readable format simply call the toString method.

Examples

// big number to decimal string
myBN.toString(10) 

// buffer to hex string
myBuffer.toString(16) 
0
0

Here is one of the many ways to do it. For this method you need source code and address of the contract.

  1. Use either metamask or enter your custom web3 provider on online ide
  2. Compile your source code
  3. Enter address of deployed contract to load on ide
  4. Enable listen to the network radio button
  5. You will be able to read input of submitted transactions
0

This is your data,

The first 4 bytes encodes the function. 0x0a19b14a

The following encodes the parameters. Each row has 32 bytes. You have 12 rows, since you have 12 parameters (for dynamic variables is more complicated and a variable can take more than one line and not keep the order (it will 'point' to its value).

000000000000000000000000ac709fcb44a43c35f0da4e3163b117a17f3770f5 0000000000000000000000000000000000000000000000878678326eac900000 0000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000bf2aa18455018000 0000000000000000000000000000000000000000000000000000000000302bdf 00000000000000000000000000000000000000000000000000000000dc51da3a 000000000000000000000000d8eeda4ee2657bb267bc35c1d60babdc5aedd269 000000000000000000000000000000000000000000000000000000000000001c b4bf0dcd37ca73bd5abce9532b033dcc6427be160683de113efca41320c27f3e 78799d84040e5c245828b1b531ef97e1af124946f4dc1db5a20cf28a7073b269 0000000000000000000000000000000000000000000000275dcc081d0c2351e0

Note that the first row is the address. the second is a uint256, in hexadecimal : 0000000000000000000000000000000000000000000000878678326eac900000

you need to convert it to decimal. The result is 2500000000000000000000.

I dont know if the bytes32 is a string. If it is, you can decode from hexadecimal to utf-8. You can try it using the website https://onlineutf8tools.com/convert-hexadecimal-to-utf8.

0

You can decode it using ethersjs. You need to remove the function selector in the data though.

const inputTypes = [
        'address',
        'uint256',
        'address',
        'uint256',
        'uint256',
        'uint256',
        'address',
        'uint8',
        'bytes32',
        'bytes32',
        'uint256'
    ]
const input = '0x' + '0x0a19b14a000000000000000000000000ac709fcb44a43c35f0da4e3163b117a17f3770f50000000000000000000000000000000000000000000000878678326eac9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000bf2aa184550180000000000000000000000000000000000000000000000000000000000000302bdf00000000000000000000000000000000000000000000000000000000dc51da3a000000000000000000000000d8eeda4ee2657bb267bc35c1d60babdc5aedd269000000000000000000000000000000000000000000000000000000000000001cb4bf0dcd37ca73bd5abce9532b033dcc6427be160683de113efca41320c27f3e78799d84040e5c245828b1b531ef97e1af124946f4dc1db5a20cf28a7073b2690000000000000000000000000000000000000000000000275dcc081d0c2351e0'.slice(10)
const decoded = ethers.utils.defaultAbiCoder.decode(inputTypes, input)
decoded.forEach((data, i) => console.log(inputTypes[i], data.toString()))
address 0xAc709FcB44a43c35F0DA4e3163b117A17F3770f5
uint256 2500000000000000000000
address 0x0000000000000000000000000000000000000000
uint256 13775000000000000000
uint256 3156959
uint256 3696351802
address 0xD8eeda4ee2657Bb267bc35C1d60babdc5aEdD269
uint8 28
bytes32 0xb4bf0dcd37ca73bd5abce9532b033dcc6427be160683de113efca41320c27f3e
bytes32 0x78799d84040e5c245828b1b531ef97e1af124946f4dc1db5a20cf28a7073b269
uint256 726181804936299500000

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.