Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Unexpected behaviour using web3.utils.toHex function #2775

Closed
@PendicGordan

Description

@PendicGordan

Hi, I'm using toHex function from web3@1.0.0-beta.33 "utils" and facing strange behaviour regarding where this function is executed. When the function is running in localhost, everything is working as expected, hex value is right because I am getting the right number out of it, but the problem occurs when DApp is deployed in production, more specifically on Amazon's S3 Bucket. There I am getting completely different hex value, which is not correct. So I will post here statement which I tested in Chrome's console, both in localhost and production environment and respectfully their results(both in hex and decimal number). Not sure if it's a web3 bug, but I'm just trying to figure out what happens here. I'll be thankful for any feedback.

Expected behavior

To get the same result both in localhost and production when web3.utils.toHex.

For the code provided down below:

Localhost:
0xf0503bbcf59aa40000 ---> Integer value: 4.433e+21

Production:
0xf0503bbcf59aa40000 ---> Integer value: 4.433e+21

Actual behavior

Getting different results in localhost and production.

For code provided down below:

Localhost:
0xf0503bbcf59aa40000 ---> Integer value: 4.433e+21

Production:
0x2266303530336262636635396161343030303022 ---> 1.9638456170702058e+47

Steps to reproduce the behavior

1. Running the statement in Chrome's console

```js
  
    web3.utils.toHex(web3.utils.toBN(4433).mul(web3.utils.toBN(10).pow(web3.utils.toBN(18))))

```

Versions

  • web3.js: web3@1.0.0-beta.33

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions