@@ -932,7 +932,11 @@ export abstract class BaseProvider extends AbstractProvider {
932
932
transaction : Deferrable < TransactionRequest > ,
933
933
blockTag ?: BlockTag | Promise < BlockTag >
934
934
) : Promise < BigNumber > => {
935
- const { usedGas, gasLimit, usedStorage } = await this . estimateResources ( transaction , blockTag ) ;
935
+ const blockHash = blockTag && blockTag !== 'latest'
936
+ ? await this . _getBlockHash ( blockTag )
937
+ : undefined ; // if blockTag is latest, avoid explicit blockhash for better performance
938
+
939
+ const { usedGas, gasLimit, usedStorage } = await this . estimateResources ( transaction , blockHash ) ;
936
940
937
941
const tx = await resolveProperties ( transaction ) ;
938
942
const data = tx . data ?. toString ( ) ?? '0x' ;
@@ -968,9 +972,13 @@ export abstract class BaseProvider extends AbstractProvider {
968
972
return encodeGasLimit ( txFee , gasPrice , gasLimit , usedStorage , isTokenTransfer ) ;
969
973
} ;
970
974
971
- _estimateGasCost = async ( extrinsic : SubmittableExtrinsic < 'promise' , ISubmittableResult > ) => {
975
+ _estimateGasCost = async (
976
+ extrinsic : SubmittableExtrinsic < 'promise' , ISubmittableResult > ,
977
+ at ?: string ,
978
+ ) => {
979
+ const apiAt = await this . api . at ( at ?? await this . bestBlockHash ) ;
980
+
972
981
const u8a = extrinsic . toU8a ( ) ;
973
- const apiAt = await this . api . at ( await this . bestBlockHash ) ;
974
982
const lenIncreaseAfterSignature = 100 ; // approximate length increase after signature
975
983
const feeDetails = await apiAt . call . transactionPaymentApi . queryFeeDetails (
976
984
u8a ,
@@ -1102,7 +1110,7 @@ export abstract class BaseProvider extends AbstractProvider {
1102
1110
*/
1103
1111
estimateResources = async (
1104
1112
transaction : Deferrable < TransactionRequest > ,
1105
- blockTag ?: BlockTag | Promise < BlockTag > ,
1113
+ blockHash ?: string ,
1106
1114
) : Promise < {
1107
1115
usedGas : BigNumber ;
1108
1116
gasLimit : BigNumber ;
@@ -1120,10 +1128,6 @@ export abstract class BaseProvider extends AbstractProvider {
1120
1128
storageLimit : STORAGE_LIMIT ,
1121
1129
} ;
1122
1130
1123
- const blockHash = blockTag && blockTag !== 'latest'
1124
- ? await this . _getBlockHash ( blockTag )
1125
- : undefined ; // if blockTag is latest, avoid explicit blockhash for better performance
1126
-
1127
1131
const gasInfo = await this . _ethCall ( txRequest , blockHash ) ;
1128
1132
const usedGas = BigNumber . from ( gasInfo . used_gas ) . toNumber ( ) ;
1129
1133
const usedStorage = gasInfo . used_storage ;
0 commit comments