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

toHex is not supporting passing Uint8Array #6957

Closed
mpetrunic opened this issue Apr 5, 2024 · 2 comments · Fixed by #6958
Closed

toHex is not supporting passing Uint8Array #6957

mpetrunic opened this issue Apr 5, 2024 · 2 comments · Fixed by #6958

Comments

@mpetrunic
Copy link
Contributor

Expected behavior

toHex(new Uint8Array([
221, 128, 128, 128, 148, 186, 248,
242, 159, 130, 231, 84, 254, 199,
252, 69, 21, 58, 104, 102, 201,
137, 255, 3, 196, 10, 128, 128,
128, 128
])) = 0xdd80808094baf8f29f82e754fec7fc45153a6866c989ff03c40a80808080

Actual behavior

It gets Json.stringified first and results in:
0x7b2230223a3232312c2231223a3132382c2232223a3132382c2233223a3132382c2234223a3134382c2235223a3138362c2236223a3234382c2237223a3234322c2238223a3135392c2239223a3133302c223130223a3233312c223131223a38342c223132223a3235342c223133223a3139392c223134223a3235322c223135223a36392c223136223a32312c223137223a35382c223138223a3130342c223139223a3130322c223230223a3230312c223231223a3133372c223232223a3235352c223233223a332c223234223a3139362c223235223a31302c223236223a3132382c223237223a3132382c223238223a3132382c223239223a3132387d

Steps to reproduce the behavior

  1. [First step]
  2. [Second step]
  3. [and so on...]

Logs

Environment

@SantiagoDevRel
Copy link

SantiagoDevRel commented Apr 5, 2024

Hi Marin!
For this you should use web3.utils.bytesToHex(new Uint8Array([])), since toHex() will read it as a string

web3.utils.bytesToHex(
  new Uint8Array([221, 128, 128, 128, 148, 186, 248, 242, 159, 130, 231, 84, 254, 199, 252, 69, 21, 58, 104, 102, 201, 137, 255, 3, 196, 10, 128, 128, 128, 128])
--> 0xdd80808094baf8f29f82e754fec7fc45153a6866c989ff03c40a80808080

web3.utils.toHex(new Uint8Array([221, 128, 128, 128, 148, 186, 248, 242, 159, 130, 231, 84, 254, 199, 252, 69, 21, 58, 104, 102, 201, 137, 255, 3, 196, 10, 128, 128, 128, 128]));
--> 0x7b2230223a3232312c2231223a3132382c2232223a3132382c2233223a3132382c2234223a3134382c2235223a3138362c2236223a3234382c2237223a3234322c2238223a3135392c2239223a3133302c223130223a3233312c223131223a38342c223132223a3235342c223133223a3139392c223134223a3235322c223135223a36392c223136223a32312c223137223a35382c223138223a3130342c223139223a3130322c223230223a3230312c223231223a3133372c223232223a3235352c223233223a332c223234223a3139362c223235223a31302c223236223a3132382c223237223a3132382c223238223a3132382c223239223a3132387d

Or the idea is that toHex() can receive the Uint8Array as well?

@mpetrunic
Copy link
Contributor Author

mpetrunic commented Apr 5, 2024

@SantiagoDevRel toHex already accepts Uint8Array type. I already opened PR #6958 which fixes bug. The alternative is to remove Uint8Array from allowed inputs (breaking change though)

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

Successfully merging a pull request may close this issue.

2 participants