MCPcopy Create free account
hub / github.com/etherspot/transaction-kit / estimate

Method estimate

lib/TransactionKit.ts:1275–1784  ·  view source on GitHub ↗

* Estimates the gas and cost for the currently selected transaction. * * This method validates the current transaction context and performs an estimation using: * - modular mode: the Etherspot Modular SDK batch and estimate flow * - delegatedEoa mode: viem account abstraction with EIP-77

({
    paymasterDetails,
    gasDetails,
    callGasLimit,
    authorization,
  }: EstimateSingleTransactionParams = {})

Source from the content-addressed store, hash-verified

1273 * - `paymasterDetails` and manual `userOpOverrides` are not supported.
1274 */
1275 async estimate({
1276 paymasterDetails,
1277 gasDetails,
1278 callGasLimit,
1279 authorization,
1280 }: EstimateSingleTransactionParams = {}): Promise<
1281 TransactionEstimateResult & IEstimatedTransaction
1282 > {
1283 if (this.selectedBatchName) {
1284 log(
1285 'estimate(): Batch selected, throwing error.',
1286 undefined,
1287 this.debugMode
1288 );
1289 this.throwError(
1290 'estimate(): Cannot estimate a batch with estimate(). Use estimateBatches() instead.'
1291 );
1292 }
1293 if (!this.selectedTransactionName || !this.workingTransaction) {
1294 const result = {
1295 to: '',
1296 chainId: this.#etherspotProvider.getChainId(),
1297 errorMessage: 'No named transaction to estimate. Call name() first.',
1298 errorType: 'VALIDATION_ERROR' as const,
1299 isEstimatedSuccessfully: false,
1300 };
1301 log(
1302 'estimate(): No named transaction, returning error result.',
1303 result,
1304 this.debugMode
1305 );
1306 return { ...result, ...this };
1307 }
1308
1309 // Only validate provider in modular mode
1310 const walletMode = this.#etherspotProvider.getWalletMode();
1311 if (walletMode === 'modular') {
1312 // Reject authorization in modular mode
1313 if (authorization) {
1314 const result = {
1315 to: this.workingTransaction?.to || '',
1316 chainId:
1317 this.workingTransaction?.chainId ??
1318 this.#etherspotProvider.getChainId(),
1319 errorMessage:
1320 'authorization is only supported in delegatedEoa mode. Remove authorization or switch walletMode to delegatedEoa.',
1321 errorType: 'VALIDATION_ERROR' as const,
1322 isEstimatedSuccessfully: false,
1323 };
1324 log(
1325 'estimate(): authorization provided in modular mode',
1326 result,
1327 this.debugMode
1328 );
1329 this.isEstimating = false;
1330 this.containsEstimatingError = true;
1331 return { ...result, ...this };
1332 }

Callers

nothing calls this directly

Calls 15

throwErrorMethod · 0.95
getProviderMethod · 0.95
logFunction · 0.90
getChainIdMethod · 0.80
getWalletModeMethod · 0.80
getBundlerClientMethod · 0.80
getPublicClientMethod · 0.80
clearUserOpsFromBatchMethod · 0.80

Tested by

no test coverage detected