abi-decoder icon indicating copy to clipboard operation
abi-decoder copied to clipboard

decodeLogs don't work with uint256 tokenId

Open ibaraki-douji opened this issue 2 years ago • 10 comments

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.

ibaraki-douji avatar Jul 07 '22 14:07 ibaraki-douji

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

R4ms3s13 avatar Jul 09 '22 15:07 R4ms3s13

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);

ibaraki-douji avatar Jul 09 '22 15:07 ibaraki-douji

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);

R4ms3s13 avatar Jul 09 '22 15:07 R4ms3s13

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

ibaraki-douji avatar Jul 09 '22 15:07 ibaraki-douji

@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)
    }

wuichen avatar Sep 13 '22 07:09 wuichen

@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

ibaraki-douji avatar Sep 21 '22 14:09 ibaraki-douji

Can i make a PR for make this fix availlable ?

devglrd avatar Oct 06 '22 12:10 devglrd

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

ibaraki-douji avatar Oct 08 '22 19:10 ibaraki-douji

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.

ChrisCates avatar Oct 26 '22 00:10 ChrisCates

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.

noahspoke avatar Dec 08 '22 04:12 noahspoke