3

I don't want to load the web3 library, I do however want to convert Either to Wei, does anyone have a JavaScript function to share.

I don't mind loading a smaller library

2
  • Web3 is the most popular for this sort of thing, but you can try ethereum-units instead Commented Oct 24, 2017 at 7:46
  • One ether is 1e18 wei. HOWEVER you will need the JavaScript big number library to be able to use numbers this large without rounding errors.
    – Alex
    Commented Oct 24, 2017 at 16:40

3 Answers 3

4

Just multiply the number of ether by 1e18 (or 10**18). Done and done!

2
  • Is there is difference in performance of manually multiplying and using the web3 method ? Commented Oct 24, 2017 at 16:28
  • 2
    FTR you actually need to multiply with 1e18 (and not 10e18)
    – rndstr
    Commented Sep 5, 2021 at 1:46
3

Accourding to this table:

  • Wei = 10^0 Wei
  • Ada = 10^3 Wei
  • Babbage = 10^6 Wei
  • Shannon = 10^9 Wei
  • Szabo = 10^12 Wei
  • Finney = 10^15 Wei
  • Ether = 10^18 Wei

1 Ether is 1^18 = 1000000000000000000 Wei.

1 Wei is 0.000000000000000001 Ether.

2

In javascript it would be wei = eth_amount*10e17. Not *10e18 . e counts as the 10 and *10e18 would multiply your eth by one order of magnitude too many!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.