@@ -42,6 +42,8 @@ custom connect button.
4242
4343### 1. Set up the project
4444
45+ Create a new project directory using Wagmi's ` create wagmi ` command with the ` vite-react ` template:
46+
4547<Tabs >
4648 <TabItem value =" pnpm " label =" pnpm " default >
4749
@@ -59,9 +61,9 @@ npm create wagmi@latest --template vite-react
5961 </TabItem >
6062</Tabs >
6163
62- This command prompts you for a project name.
64+ This prompts you for a project name.
6365For 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:
6567
6668<Tabs >
6769 <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
100102 ➜ press h + enter to show help
101103```
102104
103- #### 1.1. Review the Viem, Wagmi, and MetaMask SDK configuration
105+ ### 2. Review the Wagmi configuration
104106
105107In ` src/main.tsx ` , you can find the following ` WagmiProvider ` which takes a ` config ` and ` QueryClientProvider ` .
106108
@@ -176,7 +178,7 @@ Out of the box, they have also set up the `injected` wallet provider, `coinbaseW
176178
177179You'll replace these with the MetaMask connector for the purpose of this tutorial and testing MetaMask SDK.
178180
179- ### 2 . Update the Wagmi configuration
181+ ### 3 . Update the Wagmi configuration
180182
181183Modify this configuration to target the Linea testnet and use the MetaMask connector, which is
182184Wagmi's built-in support for MetaMask SDK:
@@ -187,7 +189,6 @@ import { lineaSepolia } from "wagmi/chains";
187189import { metaMask } from " wagmi/connectors" ;
188190
189191export const config = createConfig ({
190- multiInjectedProviderDiscovery: false ,
191192 chains: [lineaSepolia ],
192193 connectors: [
193194 metaMask ({
@@ -208,8 +209,6 @@ export const config = createConfig({
208209
209210This configures Wagmi with the following options:
210211
211- - ` multiInjectedProviderDiscovery ` disables automatic discovery of multiple injected wallets,
212- streamlining the wallet selection process.
213212- ` chains ` specifies that the dapp will connect to the Linea Sepolia network.
214213- ` connectors ` uses MetaMask as the primary wallet, and includes some dapp metadata (name, URL, and
215214 icon) for a branded user experience.
@@ -219,7 +218,7 @@ This configures Wagmi with the following options:
219218
220219This setup simplifies wallet integration and provides a smooth user experience while working with Linea Sepolia.
221220
222- ### 3 . Connect to MetaMask extension or Mobile
221+ ### 4 . Connect to MetaMask extension or Mobile
223222
224223At this point, your dapp displays, and you can connect to and disconnect from MetaMask.
225224Your connection experience will be similar to that of using the injected provider, as most web3
@@ -251,121 +250,7 @@ MetaMask Mobile.
251250 </video >
252251</p >
253252
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
368254
369255This 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