hardhat
Version:
Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
28 lines • 1.07 kB
JavaScript
import { isObject } from "@nomicfoundation/hardhat-utils/lang";
import { getRequestParams } from "../../../json-rpc.js";
/**
* This class ensures that a fixed gas price is applied to transaction requests.
* For `eth_sendTransaction` requests, it sets the gasPrice field with the value provided via the class constructor, if it hasn't been specified already.
*/
export class FixedGasPriceHandler {
#gasPrice;
constructor(gasPrice) {
this.#gasPrice = gasPrice;
}
async handle(jsonRpcRequest) {
if (jsonRpcRequest.method !== "eth_sendTransaction") {
return jsonRpcRequest;
}
const params = getRequestParams(jsonRpcRequest);
const [tx] = params;
// Temporary change to ignore EIP-1559
if (isObject(tx) &&
tx.gasPrice === undefined &&
tx.maxFeePerGas === undefined &&
tx.maxPriorityFeePerGas === undefined) {
tx.gasPrice = this.#gasPrice;
}
return jsonRpcRequest;
}
}
//# sourceMappingURL=fixed-gas-price-handler.js.map