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

decodeLogs don't work with uint256 tokenId #84

Open
ibaraki-douji opened this issue Jul 7, 2022 · 10 comments
Open

decodeLogs don't work with uint256 tokenId #84

ibaraki-douji opened this issue Jul 7, 2022 · 10 comments

Comments

@ibaraki-douji
Copy link

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
Copy link

R4ms3s13 commented Jul 9, 2022

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
Copy link
Author

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
Copy link

R4ms3s13 commented Jul 9, 2022

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
Copy link
Author

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
Copy link

wuichen commented Sep 13, 2022

@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
Copy link
Author

@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
Copy link

devglrd commented Oct 6, 2022

Can i make a PR for make this fix availlable ?

@ibaraki-douji
Copy link
Author

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

@ChrisCates
Copy link

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.

@spochart
Copy link

spochart commented Dec 8, 2022

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.

jackgoh pushed a commit to TraderDAOai/abi-decoder that referenced this issue Apr 18, 2023
kieutuan218 pushed a commit to kieutuan218/abi-decoder that referenced this issue Oct 8, 2024
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

6 participants