@@ -89,33 +89,9 @@ export class Polymath {
89
89
} ) ;
90
90
}
91
91
92
- // we use 5 gwei as a sensible default for testnets
93
- let defaultGasPrice = new BigNumber ( 5000000000 ) ;
94
-
95
- switch ( speed ) {
96
- case TransactionSpeed . Slow : {
97
- defaultGasPrice = defaultGasPrice . dividedBy ( 5 ) ;
98
- break ;
99
- }
100
- case TransactionSpeed . Medium : {
101
- defaultGasPrice = defaultGasPrice . dividedBy ( 3 / 5 ) ;
102
- break ;
103
- }
104
- case TransactionSpeed . Fast : {
105
- break ;
106
- }
107
- default : {
108
- throw new PolymathError ( {
109
- code : ErrorCode . FatalError ,
110
- message : 'Invalid transaction speed parameter' ,
111
- } ) ;
112
- }
113
- }
114
-
115
92
let contractWrappers = new PolymathBase ( {
116
93
provider,
117
94
polymathRegistryAddress,
118
- defaultGasPrice,
119
95
} ) ;
120
96
121
97
const isTestnet = await contractWrappers . isTestnet ( ) ;
@@ -158,6 +134,54 @@ export class Polymath {
158
134
} catch ( err ) {
159
135
// if the request fails, we simply use the previous default
160
136
}
137
+ } else {
138
+ let defaultGasPrice = await new Promise < BigNumber > ( ( resolve , reject ) => {
139
+ provider . sendAsync (
140
+ {
141
+ jsonrpc : '2.0' ,
142
+ id : new Date ( ) . getTime ( ) ,
143
+ params : [ ] ,
144
+ method : 'eth_gasPrice' ,
145
+ } ,
146
+ ( err , resp ) => {
147
+ if ( err ) {
148
+ reject ( err ) ;
149
+ } else if ( ! resp ) {
150
+ // we use 1 gwei as a sensible slow default for testnets
151
+ resolve ( new BigNumber ( 1000000000 ) ) ;
152
+ } else {
153
+ const price = parseInt ( resp . result , 16 ) ;
154
+ resolve ( new BigNumber ( price ) ) ;
155
+ }
156
+ }
157
+ ) ;
158
+ } ) ;
159
+
160
+ switch ( speed ) {
161
+ case TransactionSpeed . Slow : {
162
+ break ;
163
+ }
164
+ case TransactionSpeed . Medium : {
165
+ defaultGasPrice = defaultGasPrice . multipliedBy ( 3 ) ;
166
+ break ;
167
+ }
168
+ case TransactionSpeed . Fast : {
169
+ defaultGasPrice = defaultGasPrice . multipliedBy ( 5 ) ;
170
+ break ;
171
+ }
172
+ default : {
173
+ throw new PolymathError ( {
174
+ code : ErrorCode . FatalError ,
175
+ message : 'Invalid transaction speed parameter' ,
176
+ } ) ;
177
+ }
178
+ }
179
+
180
+ contractWrappers = new PolymathBase ( {
181
+ provider,
182
+ polymathRegistryAddress,
183
+ defaultGasPrice,
184
+ } ) ;
161
185
}
162
186
163
187
this . context = new Context ( {
0 commit comments