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

Bill
  • 439
  • 6
  • 18
  • Web3 is the most popular for this sort of thing, but you can try ethereum-units instead – Elena Dimitrova Oct 24 '17 at 07: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 Oct 24 '17 at 16:40

3 Answers3

4

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

BonisTech
  • 664
  • 5
  • 17
jojeyh
  • 769
  • 3
  • 8
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.

Roman Kiselenko
  • 925
  • 5
  • 13
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!

Shane Fontaine
  • 18,036
  • 20
  • 54
  • 82
jwjop1
  • 29
  • 2