gas-optimizer
v1.0.1
Published
A utility for Ethereum transaction fee optimization, automatically calculating optimal maxFeePerGas and maxPriorityFeePerGas based on network conditions and user preferences.
Maintainers
Readme
gas-optimizer
Ethereum transaction fee optimizer for fast, reliable, and budget-aware transactions. Automatically calculates optimal maxFeePerGas and maxPriorityFeePerGas.
Features
- Optimize gas fees for different speeds:
slow,normal,fast - Optional max budget for gas cost
- Send transactions using private key
- Works with Ethereum testnets and mainnet
- Server-side usage only
Installation
npm install gas-optimizerEnvironment Variables
Create a .env file:
RPC_URL=https://your_rpc_url
REC_ADDR=0xRecipientAddress
PRIVATE_KEY=your_private_keyCLI Usage
npx gas-optimizeror, if installed locally:
npm run cliThis will:
- Fetch network gas data
- Optimize fees based on speed
- Send a transaction with calculated fees
API Usage
import { sendOptimizedTransaction } from "gas-optimizer";
import { ethers } from "ethers";
const txResponse = await sendOptimizedTransaction(
{
to: "0xRecipientAddress",
value: ethers.parseEther("0.001"),
},
{
speed: "fast",
rpcUrl: process.env.RPC_URL!,
privateKey: process.env.PRIVATE_KEY!,
maxBudget: 5_000_000_000_000_000n, // optional
}
);
console.log("Transaction sent:", txResponse);Options
| Speed | Blocks | Alpha | Priority Multiplier | Percentile | | ------ | ------ | ----- | ------------------- | ---------- | | slow | 15 | 0.2 | 0.75 | 0.7 | | normal | 10 | 0.3 | 1.0 | 0.85 | | fast | 5 | 0.5 | 1.5 | 0.95 |
License
ISC
