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

web3.utils.fromWei/web3.utils.toWei bug? #7018

Open
HelloFeture opened this issue Apr 30, 2024 · 2 comments
Open

web3.utils.fromWei/web3.utils.toWei bug? #7018

HelloFeture opened this issue Apr 30, 2024 · 2 comments
Labels
4.x 4.0 related Bug Addressing a bug

Comments

@HelloFeture
Copy link

Expected behavior

the result should be same as input 0.0033086855466118933

Actual behavior

this result is 0.033086855466118933

Steps to reproduce the behavior

  1. [write js script]
  2. [run js script]
  3. [check the console log output]

Logs

const web3 = require("web3"); const inst = new web3.Web3(); console.log(inst.utils.fromWei(inst.utils.toWei("0.0033086855466118933", "ether"), "ether"));
the log output is 0.033086855466118933
expected output 0.0033086855466118933

Environment

npm 10.2.4
node 20.11.1
os Win 11

@HelloFeture
Copy link
Author

web3.js version 4.8.0

@SantiagoDevRel
Copy link
Member

Hi @HelloFeture!

I just checked and you are right, there is a difference between web3.js and using https://eth-converter.com/ in the first function toWei(), i'll ping the team to investigate this asap!

// import web3 module
import { Web3 } from "web3";

const web3 = new Web3("https://rpc2.sepolia.org");

const firstConversion = web3.utils.toWei("0.0033086855466118933", "ether"); //ether to wei
console.log(firstConversion);
//33086855466118933 => web3.js
//3308685546611893   => eth-converter

@SantiagoDevRel SantiagoDevRel added 4.x 4.0 related Bug Addressing a bug labels May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related Bug Addressing a bug
Projects
None yet
Development

No branches or pull requests

2 participants