Skip to content

Commit 07e1e42

Browse files
committed
update sdk, undo rpc client caching
1 parent 03ddcb8 commit 07e1e42

File tree

9 files changed

+42
-42
lines changed

9 files changed

+42
-42
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"pino-pretty": "^10.0.0",
7272
"prisma": "5.14.0-dev.61",
7373
"superjson": "^2.2.1",
74-
"thirdweb": "^5.35.0",
74+
"thirdweb": "^5.39.0",
7575
"uuid": "^9.0.1",
7676
"zod": "^3.23.8"
7777
},

src/db/wallets/walletNonce.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Address, eth_getTransactionCount } from "thirdweb";
1+
import { Address, eth_getTransactionCount, getRpcClient } from "thirdweb";
22
import { getChain } from "../../utils/chain";
33
import { redis } from "../../utils/redis/redis";
4-
import { getRpcRequest } from "../../utils/sdk";
4+
import { thirdwebClient } from "../../utils/sdk";
55

66
// Data type: String
77
const lastUsedNonceKey = (chainId: number, walletAddress: Address) =>
@@ -68,7 +68,10 @@ const _syncNonce = async (
6868
chainId: number,
6969
walletAddress: Address,
7070
): Promise<number> => {
71-
const rpcRequest = getRpcRequest(await getChain(chainId));
71+
const rpcRequest = getRpcClient({
72+
client: thirdwebClient,
73+
chain: await getChain(chainId),
74+
});
7275

7376
// The next unused nonce = transactionCount.
7477
const transactionCount = await eth_getTransactionCount(rpcRequest, {

src/server/routes/transaction/blockchain/sendSignedTx.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import { eth_sendRawTransaction, isHex } from "thirdweb";
4+
import { eth_sendRawTransaction, getRpcClient, isHex } from "thirdweb";
55
import { getChain } from "../../../../utils/chain";
6-
import { getRpcRequest } from "../../../../utils/sdk";
6+
import { thirdwebClient } from "../../../../utils/sdk";
77
import { createCustomError } from "../../../middleware/error";
88
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";
99
import { walletChainParamSchema } from "../../../schemas/wallet";
@@ -52,7 +52,10 @@ export async function sendSignedTransaction(fastify: FastifyInstance) {
5252
);
5353
}
5454

55-
const rpcRequest = getRpcRequest(await getChain(chainId));
55+
const rpcRequest = getRpcClient({
56+
client: thirdwebClient,
57+
chain: await getChain(chainId),
58+
});
5659
const transactionHash = await eth_sendRawTransaction(
5760
rpcRequest,
5861
signedTransaction,

src/utils/block.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { eth_blockNumber } from "thirdweb";
1+
import { eth_blockNumber, getRpcClient } from "thirdweb";
22
import { getChain } from "./chain";
33
import { redis } from "./redis/redis";
4-
import { getRpcRequest } from "./sdk";
4+
import { thirdwebClient } from "./sdk";
55

66
/**
77
* Returns the latest block number. Falls back to the last known block number.
@@ -11,7 +11,10 @@ import { getRpcRequest } from "./sdk";
1111
* @returns bigint - The latest block number.
1212
*/
1313
export const getBlockNumberish = async (chainId: number): Promise<bigint> => {
14-
const rpcRequest = getRpcRequest(await getChain(chainId));
14+
const rpcRequest = getRpcClient({
15+
client: thirdwebClient,
16+
chain: await getChain(chainId),
17+
});
1518

1619
const key = `latestBlock:${chainId}`;
1720
try {

src/utils/sdk.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { sha256HexSync } from "@thirdweb-dev/crypto";
2-
import { Chain, createThirdwebClient, getRpcClient } from "thirdweb";
2+
import { createThirdwebClient } from "thirdweb";
33
import { env } from "./env";
44

55
export const thirdwebClientId = sha256HexSync(
@@ -13,21 +13,6 @@ export const thirdwebClient = createThirdwebClient({
1313
},
1414
});
1515

16-
/**
17-
* Share rpcRequest objects to reuse cached data.
18-
*/
19-
const _rpcClientByChain: Record<number, ReturnType<typeof getRpcClient>> = {};
20-
21-
export const getRpcRequest = (chain: Chain) => {
22-
if (!(chain.id in _rpcClientByChain)) {
23-
_rpcClientByChain[chain.id] = getRpcClient({
24-
client: thirdwebClient,
25-
chain,
26-
});
27-
}
28-
return _rpcClientByChain[chain.id];
29-
};
30-
3116
/**
3217
* Helper functions to handle v4 -> v5 SDK migration.
3318
*/

src/worker/tasks/mineTransactionWorker.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Address,
55
eth_getTransactionByHash,
66
eth_getTransactionReceipt,
7+
getRpcClient,
78
} from "thirdweb";
89
import { stringify } from "thirdweb/utils";
910
import { getUserOpReceiptRaw } from "thirdweb/wallets/smart";
@@ -16,7 +17,7 @@ import { msSince } from "../../utils/date";
1617
import { env } from "../../utils/env";
1718
import { logger } from "../../utils/logger";
1819
import { redis } from "../../utils/redis/redis";
19-
import { getRpcRequest, thirdwebClient } from "../../utils/sdk";
20+
import { thirdwebClient } from "../../utils/sdk";
2021
import {
2122
ErroredTransaction,
2223
MinedTransaction,
@@ -103,7 +104,10 @@ const _handleTransaction = async (
103104
const { queueId, chainId, sentTransactionHashes } = sentTransaction;
104105

105106
// Check all sent transaction hashes since any retry could succeed.
106-
const rpcRequest = getRpcRequest(await getChain(chainId));
107+
const rpcRequest = getRpcClient({
108+
client: thirdwebClient,
109+
chain: await getChain(chainId),
110+
});
107111
const receiptResults = await Promise.allSettled(
108112
sentTransactionHashes.map((hash) =>
109113
eth_getTransactionReceipt(rpcRequest, { hash }),
@@ -173,7 +177,7 @@ const _handleUserOp = async (
173177
userOpHash,
174178
});
175179
if (userOpReceiptRaw) {
176-
const rpcRequest = getRpcRequest(chain);
180+
const rpcRequest = getRpcClient({ client: thirdwebClient, chain });
177181
const transaction = await eth_getTransactionByHash(rpcRequest, {
178182
hash: userOpReceiptRaw.receipt.transactionHash,
179183
});

src/worker/tasks/processEventLogsWorker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
eth_getBlockByHash,
1111
getContract,
1212
getContractEvents,
13+
getRpcClient,
1314
prepareEvent,
1415
} from "thirdweb";
1516
import { resolveContractAbi } from "thirdweb/contract";
@@ -20,7 +21,7 @@ import { WebhooksEventTypes } from "../../schema/webhooks";
2021
import { getChain } from "../../utils/chain";
2122
import { logger } from "../../utils/logger";
2223
import { redis } from "../../utils/redis/redis";
23-
import { getRpcRequest, thirdwebClient } from "../../utils/sdk";
24+
import { thirdwebClient } from "../../utils/sdk";
2425
import {
2526
EnqueueProcessEventLogsData,
2627
PROCESS_EVENT_LOGS_QUEUE_NAME,
@@ -249,7 +250,7 @@ const getBlockTimestamps = async (
249250
): Promise<Record<Hash, Date>> => {
250251
const now = new Date();
251252
const dedupe = Array.from(new Set(blockHashes));
252-
const rpcRequest = getRpcRequest(chain);
253+
const rpcRequest = getRpcClient({ client: thirdwebClient, chain });
253254

254255
const blocks = await Promise.all(
255256
dedupe.map(async (blockHash) => {

src/worker/tasks/processTransactionReceiptsWorker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
eth_getBlockByNumber,
99
eth_getTransactionReceipt,
1010
getContract,
11+
getRpcClient,
1112
} from "thirdweb";
1213
import { resolveContractAbi } from "thirdweb/contract";
1314
import { Abi, Hash, decodeFunctionData } from "viem";
@@ -16,7 +17,7 @@ import { WebhooksEventTypes } from "../../schema/webhooks";
1617
import { getChain } from "../../utils/chain";
1718
import { logger } from "../../utils/logger";
1819
import { redis } from "../../utils/redis/redis";
19-
import { getRpcRequest, thirdwebClient } from "../../utils/sdk";
20+
import { thirdwebClient } from "../../utils/sdk";
2021
import {
2122
EnqueueProcessTransactionReceiptsData,
2223
PROCESS_TRANSACTION_RECEIPTS_QUEUE_NAME,
@@ -95,7 +96,7 @@ const getFormattedTransactionReceipts = async ({
9596
}
9697

9798
const chain = await getChain(chainId);
98-
const rpcRequest = getRpcRequest(chain);
99+
const rpcRequest = getRpcClient({ client: thirdwebClient, chain });
99100

100101
// Get array of block numbers between `fromBlock` and `toBlock` inclusive.
101102
const blockRange: bigint[] = [];

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10203,10 +10203,10 @@ thirdweb@5.26.0:
1020310203
uqr "0.1.2"
1020410204
viem "2.10.9"
1020510205

10206-
thirdweb@^5.35.0:
10207-
version "5.35.0"
10208-
resolved "https://registry.yarnpkg.com/thirdweb/-/thirdweb-5.35.0.tgz#1a40943b4e15f0f64edff54cbca4608cdddc55b8"
10209-
integrity sha512-P/7QWeWua/QwCe1hrQ2/26Xrc0o69X/kD4QgKcUPgLQzCqRYJbRpAnXRGjTq2sxQY4Ks6Kg3cR+oTsfnT5zRHA==
10206+
thirdweb@^5.39.0:
10207+
version "5.39.0"
10208+
resolved "https://registry.yarnpkg.com/thirdweb/-/thirdweb-5.39.0.tgz#d6202dc0081ad98fbe83a32d4fdbce2842c48281"
10209+
integrity sha512-DhkdFDOjoDIvcvbSj1NxyONZxwrMoKnO/L00pbkeua9o83oY+4B3Yx/nZKC9+ZLeyY1gvWyz61/yiND92R6YhA==
1021010210
dependencies:
1021110211
"@coinbase/wallet-sdk" "4.0.3"
1021210212
"@emotion/react" "11.11.4"
@@ -10229,7 +10229,7 @@ thirdweb@^5.35.0:
1022910229
mipd "0.0.7"
1023010230
node-libs-browser "2.2.1"
1023110231
uqr "0.1.2"
10232-
viem "2.16.5"
10232+
viem "2.17.10"
1023310233

1023410234
thread-stream@^0.15.1:
1023510235
version "0.15.2"
@@ -10723,10 +10723,10 @@ viem@2.10.9:
1072310723
isows "1.0.4"
1072410724
ws "8.13.0"
1072510725

10726-
viem@2.16.5:
10727-
version "2.16.5"
10728-
resolved "https://registry.yarnpkg.com/viem/-/viem-2.16.5.tgz#9607fd47f9ae6f6a4723cf4363a966208b7a888d"
10729-
integrity sha512-QDESALYDyLSP+pIr7adH3QPZ+3is16aOVMXXZE0X1GVbgL7PDMZQ8xIF1X/B1hgyqkBl2HhMpUaq6ksUdBV/YA==
10726+
viem@2.17.10:
10727+
version "2.17.10"
10728+
resolved "https://registry.yarnpkg.com/viem/-/viem-2.17.10.tgz#0b72bc8f8b86c11d2ace03035e5c39123c9dec55"
10729+
integrity sha512-nubTeRBI3wsmYGemlg9PsbhunTSJSYUlq8VjzIQkbowCSPSd1bqzVeUU0qEOXsGtgRiFfBzXkkxFknZtBOAx/Q==
1073010730
dependencies:
1073110731
"@adraffy/ens-normalize" "1.10.0"
1073210732
"@noble/curves" "1.4.0"

0 commit comments

Comments
 (0)