diff --git a/.changeset/thick-vans-do.md b/.changeset/thick-vans-do.md new file mode 100644 index 00000000000..cbf73cbb4b6 --- /dev/null +++ b/.changeset/thick-vans-do.md @@ -0,0 +1,5 @@ +--- +"@thirdweb-dev/wagmi-adapter": patch +--- + +Fix wagmi adapter usage with account factories diff --git a/packages/wagmi-adapter/src/connector.ts b/packages/wagmi-adapter/src/connector.ts index c3d403bf056..eb16d7430dd 100644 --- a/packages/wagmi-adapter/src/connector.ts +++ b/packages/wagmi-adapter/src/connector.ts @@ -95,9 +95,10 @@ export function inAppWalletConnector( const lastChainId = await config.storage?.getItem("tw.lastChainId"); if (params?.isReconnecting) { const { autoConnect } = await import("thirdweb/wallets"); + const chainId = lastChainId || args.smartAccount?.chain?.id || 1; await autoConnect({ client, - chain: defineChain(lastChainId || 1), + chain: defineChain(chainId), wallets: [wallet], }); @@ -108,7 +109,7 @@ export function inAppWalletConnector( return { accounts: [getAddress(account.address)], - chainId: lastChainId || 1, + chainId: chainId, }; } const inAppOptions = params && "strategy" in params ? params : undefined; @@ -117,7 +118,12 @@ export function inAppWalletConnector( "Missing strategy prop, pass it to connect() when connecting to this connector", ); } - const chain = defineChain(inAppOptions?.chainId || lastChainId || 1); + const chain = defineChain( + inAppOptions?.chainId || + lastChainId || + args.smartAccount?.chain?.id || + 1, + ); const decoratedOptions = { ...inAppOptions, client,