UNPKG

hardhat

Version:

Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.

33 lines 1.37 kB
import { isObject } from "@nomicfoundation/hardhat-utils/lang"; import { getRequestParams } from "../../../json-rpc.js"; import { MultipliedGasEstimation } from "./multiplied-gas-estimation.js"; export const DEFAULT_GAS_MULTIPLIER = 1; /** * This class modifies transaction requests by automatically estimating the gas required, * applying a multiplier to the estimated gas. * * It extends the `MultipliedGasEstimation` class * to handle the gas estimation logic. If no gas value is provided in the transaction, * the gas is automatically estimated before being added to the request. */ export class AutomaticGasHandler extends MultipliedGasEstimation { #methods = new Set(["eth_sendTransaction"]); constructor(provider, gasMultiplier = DEFAULT_GAS_MULTIPLIER) { super(provider, gasMultiplier); } isSupportedMethod(jsonRpcRequest) { return this.#methods.has(jsonRpcRequest.method); } async handle(jsonRpcRequest) { if (!this.isSupportedMethod(jsonRpcRequest)) { return jsonRpcRequest; } const params = getRequestParams(jsonRpcRequest); const [tx] = params; if (isObject(tx) && tx.gas === undefined) { tx.gas = await this.getMultipliedGasEstimation(params); } return jsonRpcRequest; } } //# sourceMappingURL=automatic-gas-handler.js.map