You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Viem team 👋,
I'm encountering a confusing issue using [email protected] and [email protected] when calling writeContract on mobile devices (MetaMask via WalletConnect).
✅ Context:
I'm working on a dApp that supports multiple chains (BSC, Polygon, Base, etc.).
The user connects via MetaMask mobile (WalletConnect).
Chain bscTestnet (chainId = 97) is already added and active in MetaMask.
I'm using getWalletClient(...) from wagmi/actions to confirm chain is correct.
The full flow works fine on desktop MetaMask, but fails on mobile.
await writeContract({
abi: [...],
address: tokenAddress,
functionName: 'transfer',
args: [receiver, amount],
chainId: 97, // Also tried without this param, still fails
});
🔥 Error on mobile:
Details: Invalid chainId
Version: [email protected]
Even though:
chainId is 97
wagmiConfig.chains includes bscTestnet
getWalletClient() returns chainId 97
MetaMask is visibly on BSC Testnet
🧪 Tried:
Ensuring chainId is number
Switching chain via switchChainAsync(...)
Confirming bscTestnet is part of both Viem + Wagmi config
Logging chainId at every step (it's always 97)
Forcing chainId into writeContract(...)
Still get the same Invalid chainId error only on mobile MetaMask (WalletConnect).
❓Questions:
Is this a known limitation with MetaMask mobile / WalletConnect and Viem?
Are there extra steps to ensure WalletClient is ready for writeContract()?
Is this a timing issue between chain switching and transaction sending?
P/S: i tried the newest viem version (2.31.7) but it didn't work and has the same issue
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Viem team 👋,
I'm encountering a confusing issue using [email protected] and [email protected] when calling writeContract on mobile devices (MetaMask via WalletConnect).
✅ Context:
I'm working on a dApp that supports multiple chains (BSC, Polygon, Base, etc.).
The user connects via MetaMask mobile (WalletConnect).
Chain bscTestnet (chainId = 97) is already added and active in MetaMask.
I'm using getWalletClient(...) from wagmi/actions to confirm chain is correct.
The full flow works fine on desktop MetaMask, but fails on mobile.
📋 Code Summary:
const client = await getWalletClient(wagmiConfig, { chainId });
toastInfo(
wallet client id: ${client?.chain?.id}); // Logs: 97await writeContract({
abi: [...],
address: tokenAddress,
functionName: 'transfer',
args: [receiver, amount],
chainId: 97, // Also tried without this param, still fails
});
🔥 Error on mobile:

Details: Invalid chainId
Version: [email protected]
Even though:
chainId is 97
wagmiConfig.chains includes bscTestnet
getWalletClient() returns chainId 97
MetaMask is visibly on BSC Testnet
🧪 Tried:
Ensuring chainId is number
Switching chain via switchChainAsync(...)
Confirming bscTestnet is part of both Viem + Wagmi config
Logging chainId at every step (it's always 97)
Forcing chainId into writeContract(...)
Still get the same Invalid chainId error only on mobile MetaMask (WalletConnect).
❓Questions:
P/S: i tried the newest viem version (2.31.7) but it didn't work and has the same issue
Beta Was this translation helpful? Give feedback.
All reactions