Skip to content

Commit e10bb39

Browse files
committed
support general feeType on chain and prepareTransaction
1 parent 3233f4e commit e10bb39

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

packages/thirdweb/src/chains/types.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { FeeType } from "src/transaction/prepare-transaction.js";
2+
13
/**
24
* @chain
35
*/
@@ -26,12 +28,7 @@ export type ChainOptions = {
2628
increaseZeroByteCount?: boolean;
2729
};
2830
faucets?: Array<string>;
29-
fees?: {
30-
/**
31-
* Whether to force legacy transactions (pre EIP-1559) for this chain
32-
*/
33-
forceLegacyTransactions?: boolean;
34-
};
31+
feeType?: FeeType;
3532
};
3633

3734
/**

packages/thirdweb/src/gas/fee-data.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import type { ThirdwebClient } from "../client/client.js";
33
import { eth_getBlockByNumber } from "../rpc/actions/eth_getBlockByNumber.js";
44
import { eth_maxPriorityFeePerGas } from "../rpc/actions/eth_maxPriorityFeePerGas.js";
55
import { 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";
710
import { resolvePromisedValue } from "../utils/promise/resolve-promised-value.js";
811
import { toUnits } from "../utils/units.js";
912
import { 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(
113120
export 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
};

packages/thirdweb/src/transaction/prepare-transaction.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type StaticPrepareTransactionOptions = {
1717
maxFeePerGas?: bigint | undefined;
1818
maxPriorityFeePerGas?: bigint | undefined;
1919
maxFeePerBlobGas?: bigint | undefined;
20+
feeType?: FeeType | undefined;
2021
nonce?: number | undefined;
2122
extraGas?: bigint | undefined;
2223
// eip7702
@@ -34,6 +35,8 @@ export type StaticPrepareTransactionOptions = {
3435
};
3536
};
3637

38+
export type FeeType = "legacy" | "eip1559";
39+
3740
export type EIP712TransactionOptions = {
3841
// constant or user input
3942
gasPerPubdata?: bigint | undefined;

0 commit comments

Comments
 (0)