Skip to content

Commit ebf8194

Browse files
committed
feat: add wallet troubleshooting guide and improve wallet connection error handling
1 parent c2a953d commit ebf8194

File tree

3 files changed

+138
-6
lines changed

3 files changed

+138
-6
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,24 @@ No secrets should be committed—copy the relevant `.env.example` into `.env` lo
8484
- **Git hooks**: Husky + lint-staged ensure staged files pass lint/format before commit.
8585

8686
For detailed specs and the multi-session delivery plan, read `agent-context/technical-spec.md` and `agent-context/agent-instructions.md`.
87+
88+
---
89+
90+
## Troubleshooting
91+
92+
### Wallet Connection Issues
93+
94+
If you see an error like `"Cannot redefine property: ethereum"`, this means you have multiple wallet browser extensions installed that are conflicting.
95+
96+
**Quick fix**: Disable all wallet extensions except one (we recommend MetaMask for Moonbeam), then reload the page.
97+
98+
For detailed solutions, see [docs/WALLET_TROUBLESHOOTING.md](docs/WALLET_TROUBLESHOOTING.md).
99+
100+
### Network Configuration
101+
102+
Moonbeam Mainnet:
103+
104+
- **Chain ID**: 1284
105+
- **RPC URL**: https://rpc.api.moonbeam.network
106+
- **Currency**: GLMR
107+
- **Explorer**: https://moonscan.io

docs/WALLET_TROUBLESHOOTING.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Wallet Troubleshooting Guide
2+
3+
## Common Error: "Cannot redefine property: ethereum"
4+
5+
### What causes this error?
6+
7+
This error occurs when you have multiple wallet browser extensions installed (e.g., MetaMask, Phantom, Coinbase Wallet, etc.) that are competing to inject the `window.ethereum` object into the page.
8+
9+
**Example error:**
10+
11+
```
12+
Runtime TypeError
13+
Cannot redefine property: ethereum
14+
```
15+
16+
### Solutions
17+
18+
#### Option 1: Disable Conflicting Extensions (Recommended)
19+
20+
1. Open your browser's extension manager:
21+
- **Chrome/Brave**: `chrome://extensions/`
22+
- **Firefox**: `about:addons`
23+
- **Edge**: `edge://extensions/`
24+
25+
2. Disable all wallet extensions except the one you want to use
26+
- For Moonbeam, we recommend **MetaMask** or **Talisman**
27+
28+
3. Reload the page
29+
30+
#### Option 2: Use Different Browser Profiles
31+
32+
1. Create separate browser profiles for different wallets:
33+
- **Chrome**: Settings → Users → Add person
34+
- **Firefox**: about:profiles
35+
- **Brave**: Settings → Create profile
36+
37+
2. Install only one wallet per profile
38+
39+
#### Option 3: Change Extension Load Order
40+
41+
Some browsers allow you to change the order extensions load:
42+
43+
1. Disable all wallet extensions
44+
2. Enable only your preferred wallet first
45+
3. Reload the page before enabling other extensions
46+
47+
### Recommended Wallet Setup for Moonbeam
48+
49+
**Primary wallet**: MetaMask or Talisman
50+
51+
- Both have excellent Moonbeam support
52+
- Moonbeam is EVM-compatible, so MetaMask works natively
53+
54+
**Network Configuration**:
55+
56+
- **Network Name**: Moonbeam
57+
- **RPC URL**: `https://rpc.api.moonbeam.network`
58+
- **Chain ID**: `1284`
59+
- **Currency Symbol**: GLMR
60+
- **Block Explorer**: `https://moonscan.io`
61+
62+
### For Developers
63+
64+
If you encounter this error during development:
65+
66+
1. **Check your extensions** - Disable unnecessary wallet extensions
67+
2. **Use a clean profile** - Test in a browser profile with only one wallet
68+
3. **Clear browser cache** - Sometimes cached scripts cause conflicts
69+
4. **Check console errors** - Look for which extension is causing the conflict
70+
71+
### Still Having Issues?
72+
73+
If you continue to experience problems:
74+
75+
1. Try using a private/incognito window with extensions disabled
76+
2. Check if your wallet extension is up to date
77+
3. Verify your wallet supports the Moonbeam network (Chain ID: 1284)
78+
4. Contact support with your browser version and installed extensions list
79+
80+
### Technical Details
81+
82+
The error occurs because:
83+
84+
- Each wallet extension tries to define `window.ethereum` using `Object.defineProperty()`
85+
- The property is marked as non-configurable
86+
- When a second extension tries to redefine it, JavaScript throws a TypeError
87+
88+
This is a known limitation of the wallet injection pattern and affects all dapps, not just this one.

frontend/src/lib/wallet.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
11
export async function ensureWallet() {
2-
if (typeof window === "undefined" || !(window as typeof window & { ethereum?: unknown }).ethereum) {
3-
throw new Error("Wallet not detected");
2+
if (typeof window === "undefined") {
3+
throw new Error("Wallet not available (server-side)");
4+
}
5+
6+
const win = window as typeof window & { ethereum?: { request(args: { method: string }): Promise<unknown> } };
7+
8+
if (!win.ethereum) {
9+
throw new Error(
10+
"No wallet detected. Please install MetaMask or another Web3 wallet. " +
11+
"If you have multiple wallets installed, try disabling all but one and reload the page."
12+
);
13+
}
14+
15+
try {
16+
const ethereum = win.ethereum;
17+
const [account] = (await ethereum.request({ method: "eth_requestAccounts" })) as string[];
18+
return account;
19+
} catch (error) {
20+
if (error instanceof Error) {
21+
// Check if it's the wallet conflict error
22+
if (error.message.includes("ethereum") || error.message.includes("redefine")) {
23+
throw new Error(
24+
"Multiple wallet extensions detected. Please disable all wallet extensions except one, " +
25+
"then reload the page. See docs/WALLET_TROUBLESHOOTING.md for help."
26+
);
27+
}
28+
throw error;
29+
}
30+
throw new Error("Failed to connect wallet");
431
}
5-
const ethereum = (window as typeof window & { ethereum?: { request(args: { method: string }): Promise<unknown> } })
6-
.ethereum!;
7-
const [account] = (await ethereum.request({ method: "eth_requestAccounts" })) as string[];
8-
return account;
932
}

0 commit comments

Comments
 (0)