@@ -42,6 +42,8 @@ custom connect button.
42
42
43
43
### 1. Set up the project
44
44
45
+ Create a new project directory using Wagmi's ` create wagmi ` command with the ` vite-react ` template:
46
+
45
47
<Tabs >
46
48
<TabItem value =" pnpm " label =" pnpm " default >
47
49
@@ -59,9 +61,9 @@ npm create wagmi@latest --template vite-react
59
61
</TabItem >
60
62
</Tabs >
61
63
62
- This command prompts you for a project name.
64
+ This prompts you for a project name.
63
65
For example, use ` mmsdk-wagmi-tutorial ` .
64
- Once the CLI is complete, change directories into that project and install the node module dependencies:
66
+ Once your project is created, navigate into it and install the node module dependencies:
65
67
66
68
<Tabs >
67
69
<TabItem value =" pnpm " label =" pnpm " default >
@@ -100,7 +102,7 @@ This displays a localhost URL in your terminal for easy access to launch in your
100
102
➜ press h + enter to show help
101
103
```
102
104
103
- #### 1.1. Review the Viem, Wagmi, and MetaMask SDK configuration
105
+ ### 2. Review the Wagmi configuration
104
106
105
107
In ` src/main.tsx ` , you can find the following ` WagmiProvider ` which takes a ` config ` and ` QueryClientProvider ` .
106
108
@@ -176,7 +178,7 @@ Out of the box, they have also set up the `injected` wallet provider, `coinbaseW
176
178
177
179
You'll replace these with the MetaMask connector for the purpose of this tutorial and testing MetaMask SDK.
178
180
179
- ### 2 . Update the Wagmi configuration
181
+ ### 3 . Update the Wagmi configuration
180
182
181
183
Modify this configuration to target the Linea testnet and use the MetaMask connector, which is
182
184
Wagmi's built-in support for MetaMask SDK:
@@ -187,7 +189,6 @@ import { lineaSepolia } from "wagmi/chains";
187
189
import { metaMask } from " wagmi/connectors" ;
188
190
189
191
export const config = createConfig ({
190
- multiInjectedProviderDiscovery: false ,
191
192
chains: [lineaSepolia ],
192
193
connectors: [
193
194
metaMask ({
@@ -208,8 +209,6 @@ export const config = createConfig({
208
209
209
210
This configures Wagmi with the following options:
210
211
211
- - ` multiInjectedProviderDiscovery ` disables automatic discovery of multiple injected wallets,
212
- streamlining the wallet selection process.
213
212
- ` chains ` specifies that the dapp will connect to the Linea Sepolia network.
214
213
- ` connectors ` uses MetaMask as the primary wallet, and includes some dapp metadata (name, URL, and
215
214
icon) for a branded user experience.
@@ -219,7 +218,7 @@ This configures Wagmi with the following options:
219
218
220
219
This setup simplifies wallet integration and provides a smooth user experience while working with Linea Sepolia.
221
220
222
- ### 3 . Connect to MetaMask extension or Mobile
221
+ ### 4 . Connect to MetaMask extension or Mobile
223
222
224
223
At this point, your dapp displays, and you can connect to and disconnect from MetaMask.
225
224
Your connection experience will be similar to that of using the injected provider, as most web3
@@ -251,121 +250,7 @@ MetaMask Mobile.
251
250
</video >
252
251
</p >
253
252
254
- ### 3. Configure the SDK
255
-
256
- You can configure any [ MetaMask JavaScript SDK options] ( ../reference/sdk-js-options.md ) within the
257
- Wagmi configuration.
258
-
259
- In ` wagmi.ts ` , create a variable named ` metaMaskSDKOptions ` :
260
-
261
- ``` typescript title="wagmi.ts"
262
- const metaMaskSDKOptions = {
263
- infuraAPIKey: " <YOUR-API-KEY>" ,
264
- };
265
- ```
266
-
267
- ::: note
268
- You can use the [ ` infuraAPIKey ` ] ( ../reference/sdk-js-options.md#infuraapikey ) option to
269
- [ make direct, read-only JSON-RPC requests] ( ../how-to/make-read-only-requests.md ) .
270
- :::
271
-
272
- Pass ` metaMaskSDKOptions ` into the ` metaMask() ` function in ` connectors ` and spread its values using
273
- the ` ... ` operator:
274
-
275
- ``` typescript title="wagmi.ts"
276
- connectors : [
277
- metaMask ({
278
- dappMetadata: {
279
- name: " MetaMask SDK + Wagmi Tutorial" ,
280
- url: " https://wagmi.io" ,
281
- iconUrl: " https://wagmi.io/favicon.ico" ,
282
- },
283
- ... metaMaskSDKOptions ,
284
- }),
285
- ],
286
- ```
287
-
288
- ### 4. Use additional SDK options
289
-
290
- You can configure any number of [ SDK options] ( ../reference/sdk-js-options.md ) in the
291
- ` metaMaskSDKOptions ` object to customize the behavior of the SDK.
292
- In this section, you'll plug in options one by one to see how it affects the SDK.
293
-
294
- #### Immediately check if MetaMask is installed
295
-
296
- Use [ ` checkInstallationImmediately ` ] ( ../reference/sdk-js-options.md#checkinstallationimmediately ) to
297
- enable or disable immediately checking if MetaMask is installed in the user's browser.
298
- The default value is ` false ` .
299
- Set this to ` true ` :
300
-
301
- ``` typescript title="wagmi.ts"
302
- const metaMaskSDKOptions = {
303
- checkInstallationImmediately: true ,
304
- };
305
- ```
306
-
307
- Disable the MetaMask extension and re-load your dapp.
308
- When this option is enabled, the SDK immediately checks and notifies the user with a modal that they
309
- can either install the MetaMask extension or connect to MetaMask Mobile using a QR code.
310
-
311
- #### Check if MetaMask is installed before RPC requests
312
-
313
- Use [ ` checkInstallationOnAllCalls ` ] ( ../reference/sdk-js-options.md#checkinstallationonallcalls ) to
314
- enable or disable checking if MetaMask is installed before each JSON-RPC request.
315
- The default value is ` false ` .
316
- Set this to ` true ` :
317
-
318
- ``` typescript title="wagmi.ts"
319
- const metaMaskSDKOptions = {
320
- checkInstallationOnAllCalls: true
321
- };
322
- ```
323
-
324
- Disable the MetaMask extension and re-load your dapp.
325
- Make a read-only RPC request without the ` InfuraAPIKey ` .
326
- You'll see a similar modal as in the previous test, but it will notify the user upon making the RPC request.
327
-
328
- #### Send anonymous analytics to MetaMask
329
-
330
- Use [ ` enableDebug ` ] ( ../reference/sdk-js-options.md#enabledebug ) to enable or disable sending
331
- anonymous analytics to MetaMask to help improve the SDK.
332
- The default value is ` true ` .
333
-
334
- ``` typescript
335
- const metaMaskSDKOptions = {
336
- enableDebug: true
337
- };
338
- ```
339
-
340
- This setting does not transmit any sensitive data.
341
- It only sends information that allows MetaMask to analyze and improve the behavior and core
342
- functionality of the SDK.
343
-
344
- #### Map RPC URLs for read-only requests
345
-
346
- Use [ ` readonlyRPCMap ` ] ( ../reference/sdk-js-options.md#readonlyrpcmap ) to map RPC URLS for
347
- [ read-only RPC requests] ( ../how-to/make-read-only-requests.md ) .
348
- You can use this option in conjunction with [ ` infuraAPIKey ` ] ( ../reference/sdk-js-options.md#infuraapikey )
349
- and [ ` defaultReadOnlyChainId ` ] ( ../reference/sdk-js-options.md#defaultreadonlychainid ) .
350
-
351
- For example, you want to make read-only requests to Mainnet (chain ID ` 0x1 ` ) using the Infura API,
352
- and read-only requests to the local testnet (chain ID ` 0x539 ` ) use a custom node.
353
-
354
- ` infuraAPIKey ` provides access to various networks supported by Infura.
355
- ` readonlyRPCMap ` allows access to custom nodes and overrides Infura networks in case of a conflict.
356
- You can use both the Infura API and custom nodes to make read-only requests by specifying both options:
357
-
358
- ``` typescript
359
- const metaMaskSDKOptions = {
360
- infuraAPIKey: " <YOUR-API-KEY>" ,
361
- readonlyRPCMap: {
362
- " 0x539" : " http://localhost:8545" ,
363
- }
364
- };
365
- ```
366
-
367
- ### Conclusion
253
+ ## Conclusion
368
254
369
255
This tutorial walked you through generating a dapp using Create Wagmi, and configuring MetaMask SDK.
370
- You explored how the SDK works within a React application with Viem and Wagmi, how it behaves out of
371
- the box, and how to use a few key options to customize its behavior.
256
+ You explored how the SDK works within a React application with Wagmi, and how it behaves out of the box.
0 commit comments