Skip to content

Commit ece9b97

Browse files
committed
use v5 for local wallets on EOA
1 parent 6f8b804 commit ece9b97

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/server/utils/wallets/getLocalWallet.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { Static } from "@sinclair/typebox";
22
import { getChainByChainIdAsync } from "@thirdweb-dev/chains";
33
import { Chain, LocalWallet } from "@thirdweb-dev/wallets";
4+
import { Wallet } from "ethers";
5+
import { Address } from "thirdweb";
6+
import { Account, privateKeyToAccount } from "thirdweb/wallets";
47
import { getWalletDetails } from "../../../db/wallets/getWalletDetails";
58
import { getConfig } from "../../../utils/cache/getConfig";
69
import { networkResponseSchema } from "../../../utils/cache/getSdk";
710
import { env } from "../../../utils/env";
811
import { logger } from "../../../utils/logger";
12+
import { thirdwebClient } from "../../../utils/sdk";
913
import { LocalFileStorage } from "../storage/localStorage";
1014

1115
interface GetLocalWalletParams {
@@ -86,3 +90,22 @@ export const getLocalWallet = async ({
8690

8791
return wallet;
8892
};
93+
94+
export const getLocalWalletAccount = async (
95+
walletAddress: Address,
96+
): Promise<Account> => {
97+
const json = await new LocalFileStorage(walletAddress).getItem("");
98+
if (!json) {
99+
throw new Error(`Wallet not found for address ${walletAddress}`);
100+
}
101+
102+
const wallet = await Wallet.fromEncryptedJson(
103+
JSON.parse(json).data,
104+
env.ENCRYPTION_PASSWORD,
105+
);
106+
107+
return privateKeyToAccount({
108+
client: thirdwebClient,
109+
privateKey: wallet.privateKey,
110+
});
111+
};

src/utils/account.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { getWalletDetails } from "../db/wallets/getWalletDetails";
88
import { WalletType } from "../schema/wallet";
99
import { getAwsKmsWallet } from "../server/utils/wallets/getAwsKmsWallet";
1010
import { getGcpKmsWallet } from "../server/utils/wallets/getGcpKmsWallet";
11-
import { getLocalWallet } from "../server/utils/wallets/getLocalWallet";
11+
import {
12+
getLocalWallet,
13+
getLocalWalletAccount,
14+
} from "../server/utils/wallets/getLocalWallet";
1215
import { getSmartWallet } from "../server/utils/wallets/getSmartWallet";
1316
import { getChain } from "./chain";
1417

@@ -49,6 +52,13 @@ export const getAccount = async (args: {
4952
});
5053
break;
5154
case WalletType.local:
55+
// For non-AA
56+
// @TODO: Update all wallets to use v5 sdk and avoid ethers.
57+
if (!accountAddress) {
58+
const account = await getLocalWalletAccount(from);
59+
_accountsCache.set(cacheKey, account);
60+
return account;
61+
}
5262
wallet = await getLocalWallet({ chainId, walletAddress: from });
5363
break;
5464
default:
@@ -77,6 +87,7 @@ export const getAccount = async (args: {
7787
signer = signer.connect(provider);
7888
}
7989

90+
// @TODO: Move all wallets to use v5 SDK and avoid ethers adapter.
8091
const account = await ethers5Adapter.signer.fromEthers({
8192
signer,
8293
});

src/worker/tasks/sendTransactionWorker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ const _sendTransaction = async (
143143
client: thirdwebClient,
144144
chain,
145145
...queuedTransaction,
146+
// Stub the nonce because it will be overridden later.
147+
nonce: 1,
146148
},
147149
});
148150
} catch (e: unknown) {

0 commit comments

Comments
 (0)