Consensys / abi-decoder

Nodejs and Javascript library for decoding data params and events from ethereum transactions
GNU General Public License v3.0
633 stars 218 forks source link

decodeLogs don't work with uint256 tokenId #84

Open ibaraki-douji opened 2 years ago

ibaraki-douji commented 2 years ago

So i was trying to decode some transactions and got this error :

(node:17304) UnhandledPromiseRejectionWarning: Error: Invalid character
    at assert (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:6:21)
    at parseBase (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:274:7)
    at BN._parseBase (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:298:14)
    at BN.init [as _init] (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:105:14)
    at new BN (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:39:12)
    at new BNwrapped (C:\Users\XX\Documents\DEV\EtherScan\node_modules\web3-utils\lib\utils.js:480:16)
    at C:\Users\XX\Documents\DEV\EtherScan\node_modules\abi-decoder\index.js:190:30
    at Array.map (<anonymous>)
    at C:\Users\XX\Documents\DEV\EtherScan\node_modules\abi-decoder\index.js:157:21
    at Array.map (<anonymous>)

after some search the cause was this event :

{
  "name": "tokenId",
  "type": "uint256",
  "value": "0xfe4c845b279619589d6c4c444cc9f5d7a5d1d86aec7cb7083fcd58b57cd9b652"
}

i have other tokenId who fail too.

R4ms3s13 commented 2 years ago

So i was trying to decode some transactions and got this error :

(node:17304) UnhandledPromiseRejectionWarning: Error: Invalid character
    at assert (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:6:21)
    at parseBase (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:274:7)
    at BN._parseBase (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:298:14)
    at BN.init [as _init] (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:105:14)
    at new BN (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:39:12)
    at new BNwrapped (C:\Users\XX\Documents\DEV\EtherScan\node_modules\web3-utils\lib\utils.js:480:16)
    at C:\Users\XX\Documents\DEV\EtherScan\node_modules\abi-decoder\index.js:190:30
    at Array.map (<anonymous>)
    at C:\Users\XX\Documents\DEV\EtherScan\node_modules\abi-decoder\index.js:157:21
    at Array.map (<anonymous>)

after some search the cause was this event :

{
  "name": "tokenId",
  "type": "uint256",
  "value": "0xfe4c845b279619589d6c4c444cc9f5d7a5d1d86aec7cb7083fcd58b57cd9b652"
}

i have other tokenId who fail too.

i modified this line:
if (typeof decodedP.value === "string" && decodedP.value.startsWith("0x")) { decodedP.value = new BN(decodedP.value.slice(2), 16).toString(10); } else { decodedP.value = new BN(decodedP.value).toString(10); } remove the slice because the BN class inside transform the value from hex to decimal, so it solves my problem

ibaraki-douji commented 2 years ago

So i was trying to decode some transactions and got this error :

(node:17304) UnhandledPromiseRejectionWarning: Error: Invalid character
    at assert (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:6:21)
    at parseBase (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:274:7)
    at BN._parseBase (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:298:14)
    at BN.init [as _init] (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:105:14)
    at new BN (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:39:12)
    at new BNwrapped (C:\Users\XX\Documents\DEV\EtherScan\node_modules\web3-utils\lib\utils.js:480:16)
    at C:\Users\XX\Documents\DEV\EtherScan\node_modules\abi-decoder\index.js:190:30
    at Array.map (<anonymous>)
    at C:\Users\XX\Documents\DEV\EtherScan\node_modules\abi-decoder\index.js:157:21
    at Array.map (<anonymous>)

after some search the cause was this event :

{
  "name": "tokenId",
  "type": "uint256",
  "value": "0xfe4c845b279619589d6c4c444cc9f5d7a5d1d86aec7cb7083fcd58b57cd9b652"
}

i have other tokenId who fail too.

i modified this line: if (typeof decodedP.value === "string" && decodedP.value.startsWith("0x")) { decodedP.value = new BN(decodedP.value.slice(2), 16).toString(10); } else { decodedP.value = new BN(decodedP.value).toString(10); } remove the slice because the BN class inside transform the value from hex to decimal, so it solves my problem

oh okay I will try that. so it should be decodedP.value = new BN(decodedP.value, 16).toString(10);

R4ms3s13 commented 2 years ago

So i was trying to decode some transactions and got this error :

(node:17304) UnhandledPromiseRejectionWarning: Error: Invalid character
    at assert (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:6:21)
    at parseBase (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:274:7)
    at BN._parseBase (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:298:14)
    at BN.init [as _init] (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:105:14)
    at new BN (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:39:12)
    at new BNwrapped (C:\Users\XX\Documents\DEV\EtherScan\node_modules\web3-utils\lib\utils.js:480:16)
    at C:\Users\XX\Documents\DEV\EtherScan\node_modules\abi-decoder\index.js:190:30
    at Array.map (<anonymous>)
    at C:\Users\XX\Documents\DEV\EtherScan\node_modules\abi-decoder\index.js:157:21
    at Array.map (<anonymous>)

after some search the cause was this event :

{
  "name": "tokenId",
  "type": "uint256",
  "value": "0xfe4c845b279619589d6c4c444cc9f5d7a5d1d86aec7cb7083fcd58b57cd9b652"
}

i have other tokenId who fail too.

i modified this line: if (typeof decodedP.value === "string" && decodedP.value.startsWith("0x")) { decodedP.value = new BN(decodedP.value.slice(2), 16).toString(10); } else { decodedP.value = new BN(decodedP.value).toString(10); } remove the slice because the BN class inside transform the value from hex to decimal, so it solves my problem

oh okay I will try that. so it should be decodedP.value = new BN(decodedP.value, 16).toString(10);

without 16 like this : decodedP.value = new BN(decodedP.value).toString(10);

ibaraki-douji commented 2 years ago

So i was trying to decode some transactions and got this error :

(node:17304) UnhandledPromiseRejectionWarning: Error: Invalid character
    at assert (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:6:21)
    at parseBase (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:274:7)
    at BN._parseBase (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:298:14)
    at BN.init [as _init] (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:105:14)
    at new BN (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:39:12)
    at new BNwrapped (C:\Users\XX\Documents\DEV\EtherScan\node_modules\web3-utils\lib\utils.js:480:16)
    at C:\Users\XX\Documents\DEV\EtherScan\node_modules\abi-decoder\index.js:190:30
    at Array.map (<anonymous>)
    at C:\Users\XX\Documents\DEV\EtherScan\node_modules\abi-decoder\index.js:157:21
    at Array.map (<anonymous>)

after some search the cause was this event :

{
  "name": "tokenId",
  "type": "uint256",
  "value": "0xfe4c845b279619589d6c4c444cc9f5d7a5d1d86aec7cb7083fcd58b57cd9b652"
}

i have other tokenId who fail too.

i modified this line: if (typeof decodedP.value === "string" && decodedP.value.startsWith("0x")) { decodedP.value = new BN(decodedP.value.slice(2), 16).toString(10); } else { decodedP.value = new BN(decodedP.value).toString(10); } remove the slice because the BN class inside transform the value from hex to decimal, so it solves my problem

oh okay I will try that. so it should be decodedP.value = new BN(decodedP.value, 16).toString(10);

without 16 like this : decodedP.value = new BN(decodedP.value).toString(10);

OK ok thanks

wuichen commented 2 years ago

@R4ms3s13 @ibaraki-douji how do you get this without decoding the log? I'm also seeing invalid character error at the decoding part.

  "name": "tokenId",
  "type": "uint256",
  "value": "0xfe4c845b279619589d6c4c444cc9f5d7a5d1d86aec7cb7083fcd58b57cd9b652"
}

Where should I place these code at?

if (typeof decodedP.value === "string" && decodedP.value.startsWith("0x")) {
decodedP.value = new BN(decodedP.value.slice(2), 16).toString(10);
} else {
decodedP.value = new BN(decodedP.value).toString(10);
}

my current code looks like this

    try {
      const receipt = await success?.wait();
      console.log(receipt, 'receipt');
      abiDecoder.addABI(SingleEditionMintableCreator_ABI.abi);

      if (receipt?.logs?.length > 0) {
        const allDecodedLogs = []
        const receiptLogs = receipt.logs.map((log) => {
          let decodedLogs
          try {
            decodedLogs = abiDecoder.decodeLogs([log]);
            console.log(decodedLogs, 'decodedLogs')
            decodedLogs.map((decodedLog) => allDecodedLogs.push(decodedLog))
          } catch (err) {
            console.log(log, err)
          }
        })

      }

    } catch (error) {
      console.log(error)
      setStep(null)
      setProcessingTransaction(false)
    }
ibaraki-douji commented 1 year ago

@wuichen The code we show is inside the node_modules (./node_modules/abi-decoder/index.js) at line ~105. For the case of the logs i don't have problem with it

devglrd commented 1 year ago

Can i make a PR for make this fix availlable ?

ibaraki-douji commented 1 year ago

I don't have the fix anymore on my computer since the project was deleted.

ChrisCates commented 1 year ago

I opened a PR. But I don't think these people care about this project anymore.

I'll work on a new ABI Decoder Typescript library later. This project is written in old school Node.js anyway.

noahspoke commented 1 year ago

The solution above worked for me after removing slice. I just moved the necessary functions into my project since I don't need the ABI state management.