1
1
import { EVMWallet } from "@thirdweb-dev/wallets" ;
2
- import { Signer } from "ethers" ;
2
+ import { Signer , providers } from "ethers" ;
3
+
3
4
import { Address } from "thirdweb" ;
4
5
import { ethers5Adapter } from "thirdweb/adapters/ethers5" ;
5
6
import { Account } from "thirdweb/wallets" ;
@@ -9,8 +10,10 @@ import { getAwsKmsWallet } from "../server/utils/wallets/getAwsKmsWallet";
9
10
import { getGcpKmsWallet } from "../server/utils/wallets/getGcpKmsWallet" ;
10
11
import { getLocalWallet } from "../server/utils/wallets/getLocalWallet" ;
11
12
import { getSmartWallet } from "../server/utils/wallets/getSmartWallet" ;
13
+ import { getChain } from "./chain" ;
12
14
13
15
export const _accountsCache = new Map < string , Account > ( ) ;
16
+ export const _providerCache = new Map < number , providers . JsonRpcProvider > ( ) ;
14
17
15
18
export const getAccount = async ( args : {
16
19
chainId : number ;
@@ -53,6 +56,15 @@ export const getAccount = async (args: {
53
56
throw new Error ( `Wallet type not supported: ${ walletDetails . type } ` ) ;
54
57
}
55
58
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
+
56
68
// Get smart wallet if `accountAddress` is provided.
57
69
let signer : Signer ;
58
70
if ( accountAddress ) {
@@ -66,7 +78,10 @@ export const getAccount = async (args: {
66
78
signer = await wallet . getSigner ( ) ;
67
79
}
68
80
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
+ } ) ;
70
85
71
86
// Set cache.
72
87
_accountsCache . set ( cacheKey , account ) ;
0 commit comments