@@ -14,7 +14,7 @@ import { sendAnalyticsEvent } from 'uniswap/src/features/telemetry/send'
1414import { getContract } from 'utilities/src/contracts/getContract'
1515import { logger } from 'utilities/src/logger/logger'
1616import { useAccount } from '~/hooks/useAccount'
17- import { useEthersProvider } from '~/hooks/useEthersProvider'
17+ import { useEthersProvider , useEthersWeb3Provider } from '~/hooks/useEthersProvider'
1818
1919const { abi : MulticallABI } = UniswapInterfaceMulticallJson
2020const { abi : NFTPositionManagerABI } = NonfungiblePositionManagerJson
@@ -32,9 +32,15 @@ export function useContract<T extends Contract = Contract>({
3232 chainId ?: UniverseChainId
3333} ) : T | null {
3434 const account = useAccount ( )
35- const provider = useEthersProvider ( { chainId : chainId ?? account . chainId } )
35+ const readProvider = useEthersProvider ( { chainId : chainId ?? account . chainId } )
36+ // Signer contracts must use the wallet's provider; read contracts use the app's
37+ // read provider (UniRPC). The signer can only come from the connector client, so
38+ // `account` is attached only when that client exists — never to the read provider.
39+ const walletProvider = useEthersWeb3Provider ( { chainId : chainId ?? account . chainId } )
3640
3741 return useMemo ( ( ) => {
42+ const withSigner = Boolean ( withSignerIfPossible && account . address && walletProvider )
43+ const provider = withSigner ? walletProvider : readProvider
3844 if ( ! address || ! ABI || ! provider ) {
3945 return null
4046 }
@@ -43,7 +49,7 @@ export function useContract<T extends Contract = Contract>({
4349 address,
4450 ABI ,
4551 provider,
46- account : withSignerIfPossible && account . address ? account . address : undefined ,
52+ account : withSigner ? account . address : undefined ,
4753 } )
4854 } catch ( error ) {
4955 const wrappedError = new Error ( 'failed to get contract' , { cause : error } )
@@ -54,7 +60,7 @@ export function useContract<T extends Contract = Contract>({
5460 } )
5561 return null
5662 }
57- } , [ address , ABI , provider , withSignerIfPossible , account . address ] ) as T
63+ } , [ address , ABI , readProvider , walletProvider , withSignerIfPossible , account . address ] ) as T
5864}
5965
6066export function useTokenContract ( {
0 commit comments