diff --git a/.changeset/new-rules-buy.md b/.changeset/new-rules-buy.md new file mode 100644 index 00000000000..b0150d7790a --- /dev/null +++ b/.changeset/new-rules-buy.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Allow smart accounts to switch chains between zk and non zk chains diff --git a/packages/thirdweb/src/utils/any-evm/zksync/isZkSyncChain.ts b/packages/thirdweb/src/utils/any-evm/zksync/isZkSyncChain.ts index 2788ab897d9..f7171287840 100644 --- a/packages/thirdweb/src/utils/any-evm/zksync/isZkSyncChain.ts +++ b/packages/thirdweb/src/utils/any-evm/zksync/isZkSyncChain.ts @@ -1,5 +1,4 @@ import type { Chain } from "../../../chains/types.js"; -import { getChainMetadata } from "../../../chains/utils.js"; export async function isZkSyncChain(chain: Chain) { if (chain.id === 1337 || chain.id === 31337) { @@ -22,12 +21,5 @@ export async function isZkSyncChain(chain: Chain) { return true; } - // fallback to checking the stack on rpc - try { - const chainMetadata = await getChainMetadata(chain); - return chainMetadata.stackType === "zksync_stack"; - } catch { - // If the network check fails, assume it's not a ZkSync chain - return false; - } + return false; } diff --git a/packages/thirdweb/src/wallets/smart/smart-wallet.ts b/packages/thirdweb/src/wallets/smart/smart-wallet.ts index 5a097ecb14a..df070bb7a6b 100644 --- a/packages/thirdweb/src/wallets/smart/smart-wallet.ts +++ b/packages/thirdweb/src/wallets/smart/smart-wallet.ts @@ -2,6 +2,7 @@ import { trackConnect } from "../../analytics/track/connect.js"; import type { Chain } from "../../chains/types.js"; import { getCachedChainIfExists } from "../../chains/utils.js"; import { getContract } from "../../contract/contract.js"; +import { isZkSyncChain } from "../../utils/any-evm/zksync/isZkSyncChain.js"; import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js"; import type { Account, Wallet } from "../interfaces/wallet.js"; import { createWalletEmitter } from "../wallet-emitter.js"; @@ -202,19 +203,24 @@ export function smartWallet( if (!lastConnectOptions) { throw new Error("Cannot switch chain without a previous connection"); } - // check if factory is deployed - const factory = getContract({ - address: - createOptions.factoryAddress || - getDefaultAccountFactory(createOptions.overrides?.entrypointAddress), - chain: newChain, - client: lastConnectOptions.client, - }); - const isDeployed = await isContractDeployed(factory); - if (!isDeployed) { - throw new Error( - `Factory contract not deployed on chain: ${newChain.id}`, - ); + const isZksyncChain = await isZkSyncChain(newChain); + if (!isZksyncChain) { + // check if factory is deployed + const factory = getContract({ + address: + createOptions.factoryAddress || + getDefaultAccountFactory( + createOptions.overrides?.entrypointAddress, + ), + chain: newChain, + client: lastConnectOptions.client, + }); + const isDeployed = await isContractDeployed(factory); + if (!isDeployed) { + throw new Error( + `Factory contract not deployed on chain: ${newChain.id}`, + ); + } } const { connectSmartWallet } = await import("./index.js"); const [connectedAccount, connectedChain] = await connectSmartWallet(