Skip to content

Commit 63a80e4

Browse files
committed
bugfix: account created from ethers signer need provider
1 parent ff6485d commit 63a80e4

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/utils/account.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { EVMWallet } from "@thirdweb-dev/wallets";
2-
import { Signer } from "ethers";
2+
import { Signer, providers } from "ethers";
3+
34
import { Address } from "thirdweb";
45
import { ethers5Adapter } from "thirdweb/adapters/ethers5";
56
import { Account } from "thirdweb/wallets";
@@ -9,8 +10,10 @@ import { getAwsKmsWallet } from "../server/utils/wallets/getAwsKmsWallet";
910
import { getGcpKmsWallet } from "../server/utils/wallets/getGcpKmsWallet";
1011
import { getLocalWallet } from "../server/utils/wallets/getLocalWallet";
1112
import { getSmartWallet } from "../server/utils/wallets/getSmartWallet";
13+
import { getChain } from "./chain";
1214

1315
export const _accountsCache = new Map<string, Account>();
16+
export const _providerCache = new Map<number, providers.JsonRpcProvider>();
1417

1518
export const getAccount = async (args: {
1619
chainId: number;
@@ -53,6 +56,15 @@ export const getAccount = async (args: {
5356
throw new Error(`Wallet type not supported: ${walletDetails.type}`);
5457
}
5558

59+
// Get chain rpc provider.
60+
let provider = _providerCache.get(chainId);
61+
if (!provider) {
62+
const chain = await getChain(chainId);
63+
64+
provider = new providers.JsonRpcProvider(chain.rpc);
65+
_providerCache.set(chainId, provider);
66+
}
67+
5668
// Get smart wallet if `accountAddress` is provided.
5769
let signer: Signer;
5870
if (accountAddress) {
@@ -66,7 +78,10 @@ export const getAccount = async (args: {
6678
signer = await wallet.getSigner();
6779
}
6880

69-
const account = await ethers5Adapter.signer.fromEthers({ signer });
81+
const connectedSigner = signer.connect(provider);
82+
const account = await ethers5Adapter.signer.fromEthers({
83+
signer: connectedSigner,
84+
});
7085

7186
// Set cache.
7287
_accountsCache.set(cacheKey, account);

0 commit comments

Comments
 (0)