@@ -3,7 +3,10 @@ import type { ThirdwebClient } from "../client/client.js";
33import { eth_getBlockByNumber } from "../rpc/actions/eth_getBlockByNumber.js" ;
44import { eth_maxPriorityFeePerGas } from "../rpc/actions/eth_maxPriorityFeePerGas.js" ;
55import { getRpcClient } from "../rpc/rpc.js" ;
6- import type { PreparedTransaction } from "../transaction/prepare-transaction.js" ;
6+ import type {
7+ FeeType ,
8+ PreparedTransaction ,
9+ } from "../transaction/prepare-transaction.js" ;
710import { resolvePromisedValue } from "../utils/promise/resolve-promised-value.js" ;
811import { toUnits } from "../utils/units.js" ;
912import { getGasPrice } from "./get-gas-price.js" ;
@@ -50,11 +53,13 @@ export async function getGasOverridesForTransaction(
5053 transaction : PreparedTransaction ,
5154) : Promise < FeeDataParams > {
5255 // first check for explicit values
53- const [ maxFeePerGas , maxPriorityFeePerGas , gasPrice ] = await Promise . all ( [
54- resolvePromisedValue ( transaction . maxFeePerGas ) ,
55- resolvePromisedValue ( transaction . maxPriorityFeePerGas ) ,
56- resolvePromisedValue ( transaction . gasPrice ) ,
57- ] ) ;
56+ const [ maxFeePerGas , maxPriorityFeePerGas , gasPrice , feeType ] =
57+ await Promise . all ( [
58+ resolvePromisedValue ( transaction . maxFeePerGas ) ,
59+ resolvePromisedValue ( transaction . maxPriorityFeePerGas ) ,
60+ resolvePromisedValue ( transaction . gasPrice ) ,
61+ resolvePromisedValue ( transaction . feeType ) ,
62+ ] ) ;
5863
5964 // Exit early if the user explicitly provided enough options
6065 if ( maxFeePerGas !== undefined && maxPriorityFeePerGas !== undefined ) {
@@ -63,6 +68,7 @@ export async function getGasOverridesForTransaction(
6368 maxPriorityFeePerGas,
6469 } ;
6570 }
71+
6672 if ( typeof gasPrice === "bigint" ) {
6773 return { gasPrice } ;
6874 }
@@ -71,6 +77,7 @@ export async function getGasOverridesForTransaction(
7177 const defaultGasOverrides = await getDefaultGasOverrides (
7278 transaction . client ,
7379 transaction . chain ,
80+ feeType ,
7481 ) ;
7582
7683 if ( transaction . chain . experimental ?. increaseZeroByteCount ) {
@@ -113,10 +120,13 @@ export async function getGasOverridesForTransaction(
113120export async function getDefaultGasOverrides (
114121 client : ThirdwebClient ,
115122 chain : Chain ,
123+ feeType ?: FeeType ,
116124) {
125+ // give priority to the transaction fee type over the chain fee type
126+ const resolvedFeeType = feeType ?? chain . feeType ;
117127 // if chain is configured to force legacy transactions or is in the legacy chain list
118128 if (
119- chain . fees ?. forceLegacyTransactions ||
129+ resolvedFeeType === "legacy" ||
120130 FORCE_GAS_PRICE_CHAIN_IDS . includes ( chain . id )
121131 ) {
122132 return {
@@ -130,6 +140,7 @@ export async function getDefaultGasOverrides(
130140 maxPriorityFeePerGas : feeData . maxPriorityFeePerGas ,
131141 } ;
132142 }
143+ // TODO: resolvedFeeType here could be "EIP1559", but we could not get EIP1559 fee data. should we throw?
133144 return {
134145 gasPrice : await getGasPrice ( { client, chain, percentMultiplier : 10 } ) ,
135146 } ;
0 commit comments