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
Copy file name to clipboardExpand all lines: apps/remix-ide/src/app/plugins/prompt-blocks.ts
+90-5Lines changed: 90 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -140,7 +140,8 @@ export const invariants = {
140
140
3. **ALWAYS import React from 'react'** in any file using JSX (especially \`src/main.jsx\` and \`src/App.jsx\`).
141
141
- Example: \`import React from 'react';\` must be at the top, even if you use \`createRoot\`.
142
142
4. **ETHERS.JS PROVIDER RULES (CRITICAL):**
143
-
- **MUST USE:** Always use \`new ethers.BrowserProvider(window.ethereum)\` for both reading and writing.
143
+
- **MUST USE:** Always use \`ethers.BrowserProvider\` with a wallet provider for both reading and writing.
144
+
- **PROVIDER ACQUISITION:** Use \`window.__qdapp_getProvider ? await window.__qdapp_getProvider() : window.ethereum\` to get the provider. Store this raw provider in a ref/variable for reuse (e.g. network switching).
144
145
- **FORBIDDEN:** NEVER use \`new ethers.JsonRpcProvider\`, \`InfuraProvider\`, or \`AlchemyProvider\`.
145
146
- **FORBIDDEN:** NEVER generate code containing placeholders like 'YOUR_INFURA_KEY' or ask for API keys.
146
147
4. Use React with JSX syntax (not "text/babel" scripts).
@@ -196,7 +197,9 @@ ${functionNames}
196
197
},
197
198
198
199
/** Wallet connection and network switching patterns */
199
-
wallet: (): string=>`
200
+
wallet: (isLocalVM: boolean=false): string=>{
201
+
if(isLocalVM){
202
+
return`
200
203
**WALLET CONNECTION RULES:**
201
204
1. **Connect Wallet** button must be visible when disconnected.
202
205
2. Check \`window.ethereum\` existence before any wallet operations.
// Real network: full wallet selection rules with disconnect/switch/localStorage
232
+
return`
233
+
**WALLET CONNECTION RULES:**
234
+
1. **Connect Wallet** button must be visible in the header/navbar when disconnected.
235
+
2. **Disconnect Wallet** button must be visible in the header/navbar when connected (next to the account address).
236
+
3. **Switch Network** button must appear **only when** the connected wallet's chain ID differs from the DApp's target chain ID. Hide it when on the correct network.
6. Show truncated wallet address (e.g. \`0x1234...5678\`) when connected.
240
+
241
+
**WALLET PROVIDER ACQUISITION (CRITICAL):**
242
+
The deployed DApp uses \`window.__qdapp_getProvider()\` to discover and select wallets via EIP-6963.
243
+
Always get the raw provider like this:
244
+
\`\`\`javascript
245
+
const rawProvider = window.__qdapp_getProvider
246
+
? await window.__qdapp_getProvider()
247
+
: window.ethereum;
248
+
if (!rawProvider) {
249
+
alert('Please install a Web3 wallet (e.g. MetaMask).');
250
+
return;
251
+
}
252
+
const provider = new ethers.BrowserProvider(rawProvider);
253
+
\`\`\`
254
+
**Store \`rawProvider\` in a React ref** (e.g. \`rawProviderRef.current = rawProvider\`) so you can reuse it for network switching without calling \`__qdapp_getProvider\` again.
255
+
256
+
**🚨 CHAIN ID COMPARISON (CRITICAL — prevents wrong-network false positive):**
257
+
- ethers.js v6 returns \`network.chainId\` as a **BigInt** (e.g. \`11155111n\`).
0 commit comments