Skip to content

Commit 842c37e

Browse files
committed
update prepare transaction to use type instead of feetype
1 parent b2b1e46 commit 842c37e

File tree

5 files changed

+73
-46
lines changed

5 files changed

+73
-46
lines changed

packages/thirdweb/src/adapters/ethers5.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import type { ThirdwebClient } from "../client/client.js";
99
import { type ThirdwebContract, getContract } from "../contract/contract.js";
1010
import { toSerializableTransaction } from "../transaction/actions/to-serializable-transaction.js";
1111
import { waitForReceipt } from "../transaction/actions/wait-for-tx-receipt.js";
12-
import type { PreparedTransaction } from "../transaction/prepare-transaction.js";
12+
import {
13+
type PreparedTransaction,
14+
TransactionTypeMap,
15+
} from "../transaction/prepare-transaction.js";
1316
import type { SerializableTransaction } from "../transaction/serialize-transaction.js";
1417
import { toHex } from "../utils/encoding/hex.js";
1518
import type { Account } from "../wallets/interfaces/wallet.js";
@@ -483,6 +486,7 @@ export async function toEthersSigner(
483486

484487
const response: ethers5.ethers.providers.TransactionResponse = {
485488
...serialized,
489+
type: serialized.type ? TransactionTypeMap[serialized.type] : undefined,
486490
nonce: Number(serialized.nonce ?? 0),
487491
from: account.address,
488492
maxFeePerGas: serialized.maxFeePerGas

packages/thirdweb/src/chains/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { FeeType } from "../transaction/prepare-transaction.js";
1+
import type { FeeType } from "../gas/fee-data.js";
22

33
/**
44
* @chain

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ 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 {
7-
FeeType,
8-
PreparedTransaction,
9-
} from "../transaction/prepare-transaction.js";
6+
import type { PreparedTransaction } from "../transaction/prepare-transaction.js";
107
import { resolvePromisedValue } from "../utils/promise/resolve-promised-value.js";
118
import { toUnits } from "../utils/units.js";
129
import { getGasPrice } from "./get-gas-price.js";
@@ -54,12 +51,12 @@ export async function getGasOverridesForTransaction(
5451
transaction: PreparedTransaction,
5552
): Promise<FeeDataParams> {
5653
// first check for explicit values
57-
const [maxFeePerGas, maxPriorityFeePerGas, gasPrice, feeType] =
54+
const [maxFeePerGas, maxPriorityFeePerGas, gasPrice, type] =
5855
await Promise.all([
5956
resolvePromisedValue(transaction.maxFeePerGas),
6057
resolvePromisedValue(transaction.maxPriorityFeePerGas),
6158
resolvePromisedValue(transaction.gasPrice),
62-
resolvePromisedValue(transaction.feeType),
59+
resolvePromisedValue(transaction.type),
6360
]);
6461

6562
// Exit early if the user explicitly provided enough options
@@ -78,7 +75,7 @@ export async function getGasOverridesForTransaction(
7875
const defaultGasOverrides = await getDefaultGasOverrides(
7976
transaction.client,
8077
transaction.chain,
81-
feeType,
78+
type === "legacy" ? "legacy" : "eip1559", // 7702, 2930, and eip1559 all qualify as "eip1559" fee type
8279
);
8380

8481
if (transaction.chain.experimental?.increaseZeroByteCount) {
@@ -109,6 +106,8 @@ export async function getGasOverridesForTransaction(
109106
};
110107
}
111108

109+
export type FeeType = "legacy" | "eip1559";
110+
112111
/**
113112
* Retrieves the default gas overrides for a given client and chain ID.
114113
* If the fee data contains both maxFeePerGas and maxPriorityFeePerGas, it returns an object with those values.

packages/thirdweb/src/transaction/actions/to-serializable-transaction.ts

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -75,42 +75,52 @@ export async function toSerializableTransaction(
7575
const rpcRequest = getRpcClient(options.transaction);
7676
const chainId = options.transaction.chain.id;
7777
const from = options.from;
78-
let [data, nonce, gas, feeData, to, accessList, value, authorizationList] =
79-
await Promise.all([
80-
encode(options.transaction),
81-
(async () => {
82-
// if the user has specified a nonce, use that
83-
const resolvedNonce = await resolvePromisedValue(
84-
options.transaction.nonce,
85-
);
86-
if (resolvedNonce !== undefined) {
87-
return resolvedNonce;
88-
}
78+
let [
79+
data,
80+
nonce,
81+
gas,
82+
feeData,
83+
to,
84+
accessList,
85+
value,
86+
authorizationList,
87+
type,
88+
] = await Promise.all([
89+
encode(options.transaction),
90+
(async () => {
91+
// if the user has specified a nonce, use that
92+
const resolvedNonce = await resolvePromisedValue(
93+
options.transaction.nonce,
94+
);
95+
if (resolvedNonce !== undefined) {
96+
return resolvedNonce;
97+
}
8998

90-
return from // otherwise get the next nonce (import the method to do so)
91-
? await import("../../rpc/actions/eth_getTransactionCount.js").then(
92-
({ eth_getTransactionCount }) =>
93-
eth_getTransactionCount(rpcRequest, {
94-
address:
95-
typeof from === "string"
96-
? getAddress(from)
97-
: getAddress(from.address),
98-
blockTag: "pending",
99-
}),
100-
)
101-
: undefined;
102-
})(),
103-
// takes the same options as the sendTransaction function thankfully!
104-
estimateGas({
105-
...options,
106-
from: options.from,
107-
}),
108-
getGasOverridesForTransaction(options.transaction),
109-
resolvePromisedValue(options.transaction.to),
110-
resolvePromisedValue(options.transaction.accessList),
111-
resolvePromisedValue(options.transaction.value),
112-
resolvePromisedValue(options.transaction.authorizationList),
113-
]);
99+
return from // otherwise get the next nonce (import the method to do so)
100+
? await import("../../rpc/actions/eth_getTransactionCount.js").then(
101+
({ eth_getTransactionCount }) =>
102+
eth_getTransactionCount(rpcRequest, {
103+
address:
104+
typeof from === "string"
105+
? getAddress(from)
106+
: getAddress(from.address),
107+
blockTag: "pending",
108+
}),
109+
)
110+
: undefined;
111+
})(),
112+
// takes the same options as the sendTransaction function thankfully!
113+
estimateGas({
114+
...options,
115+
from: options.from,
116+
}),
117+
getGasOverridesForTransaction(options.transaction),
118+
resolvePromisedValue(options.transaction.to),
119+
resolvePromisedValue(options.transaction.accessList),
120+
resolvePromisedValue(options.transaction.value),
121+
resolvePromisedValue(options.transaction.authorizationList),
122+
resolvePromisedValue(options.transaction.type),
123+
]);
114124

115125
const extraGas = await resolvePromisedValue(options.transaction.extraGas);
116126
if (extraGas) {
@@ -126,6 +136,7 @@ export async function toSerializableTransaction(
126136
accessList,
127137
value,
128138
authorizationList,
139+
type,
129140
...feeData,
130141
} satisfies SerializableTransaction;
131142
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type StaticPrepareTransactionOptions = {
1717
maxFeePerGas?: bigint | undefined;
1818
maxPriorityFeePerGas?: bigint | undefined;
1919
maxFeePerBlobGas?: bigint | undefined;
20-
feeType?: FeeType | undefined;
20+
type?: undefined | TransactionType;
2121
nonce?: number | undefined;
2222
extraGas?: bigint | undefined;
2323
// eip7702
@@ -35,7 +35,20 @@ export type StaticPrepareTransactionOptions = {
3535
};
3636
};
3737

38-
export type FeeType = "legacy" | "eip1559";
38+
export type TransactionType =
39+
| "legacy"
40+
| "eip1559"
41+
| "eip2930"
42+
| "eip4844"
43+
| "eip7702";
44+
45+
export const TransactionTypeMap: Record<TransactionType, number> = {
46+
legacy: 0,
47+
eip1559: 1,
48+
eip2930: 2,
49+
eip4844: 3,
50+
eip7702: 4,
51+
};
3952

4053
export type EIP712TransactionOptions = {
4154
// constant or user input

0 commit comments

Comments
 (0)