Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot decode tx data #56

Open
kilicbaran opened this issue Jul 5, 2020 · 4 comments
Open

Cannot decode tx data #56

kilicbaran opened this issue Jul 5, 2020 · 4 comments

Comments

@kilicbaran
Copy link

This is somewhat an edge case but the ERC20 token transfer for this transaction cannot be decoded. I am not sure whether I should open an issue here or @ethersproject/abi.

Sample Code

const abiDecoder = require('abi-decoder');
const testABI = [{
    "constant": false,
    "inputs": [
        {
            "name": "_to",
            "type": "address"
        },
        {
            "name": "_value",
            "type": "uint256"
        }
    ],
    "name": "transfer",
    "outputs": [
        {
            "name": "",
            "type": "bool"
        }
    ],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
}];
abiDecoder.addABI(testABI);
const testData = "0xa9059cbb0000000000000000000000043f47038d2b20566700a38cd718a537103f7696c9000000000000000000000000000000000000000000000000000000000903c63c";
const decodedData = abiDecoder.decodeMethod(testData);
console.log(decodedData);

Exception

/home/ubuntu/node_modules/@ethersproject/abi/lib/coders/array.js:139
                get: function () { throw value; }
                                   ^

_to: value out of range (argument="value", value=20, code=INVALID_ARGUMENT, version=bytes/5.0.1)
    at Logger.makeError (/home/ubuntu/node_modules/@ethersproject/logger/lib/index.js:179:21)
    at Logger.throwError (/home/ubuntu/node_modules/@ethersproject/logger/lib/index.js:188:20)
    at Logger.throwArgumentError (/home/ubuntu/node_modules/@ethersproject/logger/lib/index.js:191:21)
    at Object.hexZeroPad (/home/ubuntu/node_modules/@ethersproject/bytes/lib/index.js:263:16)
    at AddressCoder.decode (/home/ubuntu/node_modules/@ethersproject/abi/lib/coders/address.js:34:45)
    at /home/ubuntu/node_modules/@ethersproject/abi/lib/coders/array.js:93:31
    at Array.forEach (<anonymous>)
    at Object.unpack (/home/ubuntu/node_modules/@ethersproject/abi/lib/coders/array.js:71:12)
    at TupleCoder.decode (/home/ubuntu/node_modules/@ethersproject/abi/lib/coders/tuple.js:39:49)
    at AbiCoder.decode (/home/ubuntu/node_modules/@ethersproject/abi/lib/abi-coder.js:93:22) {
  reason: 'value out of range',
  code: 'INVALID_ARGUMENT',
  argument: 'value',
  value: 20,
  baseType: 'address',
  name: '_to',
  type: 'address'
}

I think that there is a typo in the input data for the address parameter and this causes a problem. There is a 4 instead of 0 (I added spaces before and after to make it more readable.)

Function signiture: 0xa9059cbb
Address: 00000000000000000000000 4 3f47038d2b20566700a38cd718a537103f7696c9
Value: 000000000000000000000000000000000000000000000000000000000903c63c

@Alex314Ru
Copy link

I'm facing the same issue with this transaction at this moment.

@aminlatifi
Copy link

I have the same problem!
Actually w had developed our decoder and were not using abi-decoder. Recently our code wasn't working and I tried abi-decoder as an alternative solution to see what happens! The same problem happens again.

Finally I fill all data with zero except the part I need the its value, it meets my requirement.

  const [log] = logs;
  const { data } = log;
  // Just keep homeTx
  log.data = `0x${'0'.repeat(128)}${data.substring(130, 130 + 64)}${'0'.repeat(
    data.length - 2 - 128 - 64,
  )};

@dapplion
Copy link

dapplion commented Aug 9, 2020

The transaction linked above is not constructed correctly (has a 0x04 byte prefixed to the address) but that shouldn't make the decode crash. Actually the code that is crashing is @ethersproject/abi so you may want to open an issue there saying that @ethersproject/abi should not assume that address parameters are prefixed by zeros

@ricmoo
Copy link

ricmoo commented Sep 8, 2020

I've added support in ethers 5.0.12 for supporting legacy Solidity 0.4 external event data.

For more details, please see ethers-io/ethers.js#891.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants