Skip to content

Commit f655657

Browse files
[SDK] fix: EIP1193 provider value filtering in transactions (#6449)
1 parent 109f250 commit f655657

File tree

3 files changed

+51
-26
lines changed

3 files changed

+51
-26
lines changed

.changeset/small-taxis-jog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix EIP1193 provider adapter filtering out value from transactions

packages/thirdweb/src/adapters/eip1193/to-eip1193.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { TEST_ACCOUNT_A } from "~test/test-wallets.js";
55
import { typedData } from "~test/typed-data.js";
66
import { ANVIL_CHAIN } from "../../../test/src/chains.js";
77
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
8+
import { waitForReceipt } from "../../transaction/actions/wait-for-tx-receipt.js";
89
import { prepareTransaction } from "../../transaction/prepare-transaction.js";
910
import type { Account, Wallet } from "../../wallets/interfaces/wallet.js";
11+
import { getWalletBalance } from "../../wallets/utils/getWalletBalance.js";
1012
import { createWalletEmitter } from "../../wallets/wallet-emitter.js";
1113
import { toProvider } from "./to-eip1193.js";
1214

@@ -117,12 +119,33 @@ describe("toProvider", () => {
117119
to: TEST_WALLET_B,
118120
});
119121

122+
const balanceBefore = await getWalletBalance({
123+
client: TEST_CLIENT,
124+
chain: ANVIL_CHAIN,
125+
address: mockAccount.address,
126+
});
127+
120128
const result = await provider.request({
121129
method: "eth_sendTransaction",
122130
params: [tx],
123131
});
124132

125133
expect(ox__Hex.validate(result)).toBe(true);
134+
const receipt = await waitForReceipt({
135+
client: TEST_CLIENT,
136+
chain: ANVIL_CHAIN,
137+
transactionHash: result,
138+
});
139+
140+
expect(receipt.status).toBe("success");
141+
142+
const balanceAfter = await getWalletBalance({
143+
client: TEST_CLIENT,
144+
chain: ANVIL_CHAIN,
145+
address: mockAccount.address,
146+
});
147+
148+
expect(balanceAfter.value).toBeLessThan(balanceBefore.value);
126149
});
127150

128151
test("should handle eth_estimateGas", async () => {

packages/thirdweb/src/wallets/in-app/core/wallet/enclave-wallet.ts

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ThirdwebClient } from "../../../../client/client.js";
55
import { eth_sendRawTransaction } from "../../../../rpc/actions/eth_sendRawTransaction.js";
66
import { getRpcClient } from "../../../../rpc/rpc.js";
77
import { getAddress } from "../../../../utils/address.js";
8-
import { type Hex, toHex } from "../../../../utils/encoding/hex.js";
8+
import { type Hex, isHex, toHex } from "../../../../utils/encoding/hex.js";
99
import { parseTypedData } from "../../../../utils/signatures/helpers/parse-typed-data.js";
1010
import type { Prettify } from "../../../../utils/type-utils.js";
1111
import type {
@@ -141,39 +141,32 @@ export class EnclaveWallet implements IWebWallet {
141141
const transaction: Record<string, Hex | number | undefined> = {
142142
to: tx.to ? getAddress(tx.to) : undefined,
143143
data: tx.data,
144-
value: typeof tx.value === "bigint" ? toHex(tx.value) : undefined,
145-
gas:
146-
typeof tx.gas === "bigint"
147-
? toHex(tx.gas + tx.gas / BigInt(10))
148-
: undefined, // Add a 10% buffer to gas
144+
value: hexlify(tx.value),
145+
gas: hexlify(tx.gas),
149146
nonce:
150-
typeof tx.nonce === "number"
151-
? toHex(tx.nonce)
152-
: toHex(
153-
await import(
154-
"../../../../rpc/actions/eth_getTransactionCount.js"
155-
).then(({ eth_getTransactionCount }) =>
156-
eth_getTransactionCount(rpcRequest, {
157-
address: getAddress(this.address),
158-
blockTag: "pending",
159-
}),
160-
),
161-
),
147+
hexlify(tx.nonce) ||
148+
toHex(
149+
await import(
150+
"../../../../rpc/actions/eth_getTransactionCount.js"
151+
).then(({ eth_getTransactionCount }) =>
152+
eth_getTransactionCount(rpcRequest, {
153+
address: getAddress(this.address),
154+
blockTag: "pending",
155+
}),
156+
),
157+
),
162158
chainId: toHex(tx.chainId),
163159
};
164160

165-
if (typeof tx.maxFeePerGas === "bigint") {
166-
transaction.maxFeePerGas = toHex(tx.maxFeePerGas);
167-
transaction.maxPriorityFeePerGas =
168-
typeof tx.maxPriorityFeePerGas === "bigint"
169-
? toHex(tx.maxPriorityFeePerGas)
170-
: undefined;
161+
if (hexlify(tx.maxFeePerGas)) {
162+
transaction.maxFeePerGas = hexlify(tx.maxFeePerGas);
163+
transaction.maxPriorityFeePerGas = hexlify(tx.maxPriorityFeePerGas);
171164
transaction.type = 2;
172165
} else {
173-
transaction.gasPrice =
174-
typeof tx.gasPrice === "bigint" ? toHex(tx.gasPrice) : undefined;
166+
transaction.gasPrice = hexlify(tx.gasPrice);
175167
transaction.type = 0;
176168
}
169+
177170
return signEnclaveTransaction({
178171
client,
179172
storage,
@@ -253,3 +246,7 @@ export class EnclaveWallet implements IWebWallet {
253246
};
254247
}
255248
}
249+
250+
function hexlify(value: string | number | bigint | undefined) {
251+
return value === undefined || isHex(value) ? value : toHex(value);
252+
}

0 commit comments

Comments
 (0)