@nomicfoundation/ethereumjs-tx
Version:
Implementation of the various Ethereum Transaction Types
10 lines (8 loc) • 376 B
text/typescript
import type { EIP1559CompatibleTx } from '../types.js'
export function getUpfrontCost(tx: EIP1559CompatibleTx, baseFee: bigint): bigint {
const prio = tx.maxPriorityFeePerGas
const maxBase = tx.maxFeePerGas - baseFee
const inclusionFeePerGas = prio < maxBase ? prio : maxBase
const gasPrice = inclusionFeePerGas + baseFee
return tx.gasLimit * gasPrice + tx.value
}