@@ -38,39 +38,37 @@ import {
38
38
InvalidUnitError ,
39
39
} from 'web3-errors' ;
40
40
41
- const base = BigInt ( 10 ) ;
42
- const expo10 = ( expo : number ) => base ** BigInt ( expo ) ;
43
-
44
41
// Ref: https://ethdocs.org/en/latest/ether.html
42
+ // Note: this could be simplified using ** operator, but babel does not handle it well (https://github.com/babel/babel/issues/13109)
45
43
/** @internal */
46
44
export const ethUnitMap = {
47
- noether : BigInt ( '0' ) ,
45
+ noether : BigInt ( 0 ) ,
48
46
wei : BigInt ( 1 ) ,
49
- kwei : expo10 ( 3 ) ,
50
- Kwei : expo10 ( 3 ) ,
51
- babbage : expo10 ( 3 ) ,
52
- femtoether : expo10 ( 3 ) ,
53
- mwei : expo10 ( 6 ) ,
54
- Mwei : expo10 ( 6 ) ,
55
- lovelace : expo10 ( 6 ) ,
56
- picoether : expo10 ( 6 ) ,
57
- gwei : expo10 ( 9 ) ,
58
- Gwei : expo10 ( 9 ) ,
59
- shannon : expo10 ( 9 ) ,
60
- nanoether : expo10 ( 9 ) ,
61
- nano : expo10 ( 9 ) ,
62
- szabo : expo10 ( 12 ) ,
63
- microether : expo10 ( 12 ) ,
64
- micro : expo10 ( 12 ) ,
65
- finney : expo10 ( 15 ) ,
66
- milliether : expo10 ( 15 ) ,
67
- milli : expo10 ( 15 ) ,
68
- ether : expo10 ( 18 ) ,
69
- kether : expo10 ( 21 ) ,
70
- grand : expo10 ( 21 ) ,
71
- mether : expo10 ( 24 ) ,
72
- gether : expo10 ( 27 ) ,
73
- tether : expo10 ( 30 ) ,
47
+ kwei : BigInt ( 1000 ) ,
48
+ Kwei : BigInt ( 1000 ) ,
49
+ babbage : BigInt ( 1000 ) ,
50
+ femtoether : BigInt ( 1000 ) ,
51
+ mwei : BigInt ( 1000000 ) ,
52
+ Mwei : BigInt ( 1000000 ) ,
53
+ lovelace : BigInt ( 1000000 ) ,
54
+ picoether : BigInt ( 1000000 ) ,
55
+ gwei : BigInt ( 1000000000 ) ,
56
+ Gwei : BigInt ( 1000000000 ) ,
57
+ shannon : BigInt ( 1000000000 ) ,
58
+ nanoether : BigInt ( 1000000000 ) ,
59
+ nano : BigInt ( 1000000000 ) ,
60
+ szabo : BigInt ( 1000000000000 ) ,
61
+ microether : BigInt ( 1000000000000 ) ,
62
+ micro : BigInt ( 1000000000000 ) ,
63
+ finney : BigInt ( 1000000000000000 ) ,
64
+ milliether : BigInt ( 1000000000000000 ) ,
65
+ milli : BigInt ( 1000000000000000 ) ,
66
+ ether : BigInt ( '1000000000000000000' ) ,
67
+ kether : BigInt ( '1000000000000000000000' ) ,
68
+ grand : BigInt ( '1000000000000000000000' ) ,
69
+ mether : BigInt ( '1000000000000000000000000' ) ,
70
+ gether : BigInt ( '1000000000000000000000000000' ) ,
71
+ tether : BigInt ( '1000000000000000000000000000000' ) ,
74
72
} ;
75
73
76
74
export type EtherUnits = keyof typeof ethUnitMap ;
0 commit comments