2
2
sidebar_label : Dynamic SDK
3
3
description : Quickstart guide for using MetaMask SDK and Dynamic SDK.
4
4
toc_max_heading_level : 2
5
- keywords : [connect, MetaMask, Dynamic, SDK, dapp]
5
+ keywords : [connect, MetaMask, Dynamic, SDK, dapp, Wallet SDK ]
6
6
---
7
7
8
8
# Connect to MetaMask using Dynamic SDK
9
9
10
10
Get started with MetaMask SDK and [ Dynamic SDK] ( https://docs.dynamic.xyz/introduction/welcome ) .
11
11
You can use MetaMask SDK features directly within Dynamic SDK.
12
- Set up the SDKs in one of the following ways:
13
-
14
- - [ SDK CLI] ( #set-up-using-the-cli ) - Use the CLI to scaffold a Next.js and Dynamic dapp.
15
- - [ Quickstart template] ( #set-up-using-a-template ) - Clone the template to set up a Next.js and Dynamic dapp.
16
- - [ Manual setup] ( #set-up-manually ) - Set up Dynamic SDK in an existing dapp.
17
-
18
- <details >
19
- <summary >Project structure</summary >
20
- <div >
21
- The project you set up using the CLI or template has the following structure:
22
-
23
- ``` text
24
- ├── app/
25
- │ ├── providers.tsx # Main providers configuration
26
- │ └── layout.tsx # Root layout with providers
27
- ├── components/
28
- │ ├── Navbar.tsx # Navigation with wallet connection
29
- │ └── Hero.tsx # Hero section with wallet status
30
- ├── wagmi.config.ts # Wagmi configuration
31
- ├── next.config.ts # Next.js configuration
32
- └── package.json # Project dependencies
33
- ```
34
- </div >
35
- </details >
12
+ You can [ download the quickstart template] ( #set-up-using-a-template ) or [ manually set up the SDKs] ( #set-up-manually ) in an existing dapp.
36
13
37
14
<p align =" center " >
38
- <img src={require("../_ assets/quickstart-dynamic.png").default} alt="Dynamic SDK Quickstart" width="600px" />
15
+ <a href =" https://metamask-dynamic-demo.vercel.app/ " target =" _blank " >
16
+ <img src={require("../_assets/quickstart-dynamic.png").default} alt="Dynamic SDK Quickstart" width="600px" />
17
+ </a >
39
18
</p >
40
19
41
20
## Prerequisites
42
21
43
22
- [ Node.js] ( https://nodejs.org/ ) version 19 or later installed.
44
- - A package manager installed.
45
- The examples in this quickstart use [ pnpm] ( https://pnpm.io/installation ) .
23
+ - A package manager installed, such as [ npm] ( https://docs.npmjs.com/downloading-and-installing-node-js-and-npm ) , [ Yarn] ( https://yarnpkg.com/ ) , [ pnpm] ( https://pnpm.io/installation ) , or [ bun] ( https://bun.sh/ ) .
46
24
- [ MetaMask] ( https://metamask.io/ ) installed in your browser or on mobile.
47
25
- A [ Dynamic Environment ID] ( https://app.dynamic.xyz/ ) .
48
26
49
- ## Set up using the CLI
50
-
51
- 1 . Run the CLI command, replacing ` <project-name> ` with your project name:
52
-
53
- ``` bash
54
- npx @consensys/create-web3-app < project-name>
55
- ```
56
-
57
- 2. Select the Dynamic Quickstart template:
58
-
59
- ` ` ` bash
60
- ? Please select the template you want to use:
61
- MetaMask < -> Next.js (Wagmi) Quickstart (Recommended)
62
- MetaMask < -> Web3Auth Quickstart
63
- ❯ MetaMask < -> Dynamic Quickstart
64
- ` ` `
65
-
66
- 3. Select your preferred blockchain tooling if your project requires it:
67
-
68
- ` ` ` bash
69
- ? Would you like to include blockchain tooling? (Use arrow keys)
70
- ❯ HardHat
71
- Foundry
72
- None
73
- ` ` `
74
-
75
- 4. Select your preferred package manager.
76
- We recommend pnpm for speed and efficiency:
77
-
78
- ` ` ` bash
79
- ? Please select the package manager you want to use:
80
- Yarn
81
- NPM
82
- ❯ pnpm
83
- ` ` `
84
-
85
- 5. Select to enter your Dynamic Environment ID in the command prompt:
27
+ ## Set up using a template
86
28
87
- ` ` ` bash
88
- ? The selected template uses Dynamic.xyz. You' ll need a Dynamic Environment ID
89
- added to a .env file. Would you like to add it now? You can get one from
90
- https://app.dynamic.xyz/dashboard/developer/api Yes
91
- ? Please paste your Dynamic Environment ID:
92
- ```
29
+ 1 . Download the [ MetaMask SDK + Dynamic SDK template] ( https://github.com/MetaMask/metamask-sdk-examples/tree/main/partners/dynamic ) :
93
30
94
- 5. The CLI will take a few minutes to set up your project.
95
- Once complete, you can run the project using the following command in `<project-name>/packages/site`:
31
+ ``` bash
32
+ npx degit MetaMask/metamask-sdk-examples/partners/dynamic metamask-dynamic
33
+ ```
96
34
97
- ```bash
98
- pnpm run dev
99
- ```
35
+ 2 . Navigate into the repository:
100
36
101
- You' ve successfully set up MetaMask SDK and Dynamic SDK.
102
- See how to [use the combined SDKs](# usage).
37
+ ``` bash
38
+ cd metamask-dynamic
39
+ ```
103
40
104
- # # Set up using a template
41
+ <details >
42
+ <summary >Degit vs. Git clone</summary >
43
+ <div >
105
44
106
- 1. Download the [MetaMask SDK + Dynamic SDK template](https://github.com/MetaMask/metamask-dynamic):
45
+ ` degit ` is a tool that enables cloning only the directory structure from a GitHub repository, without retrieving the entire repository.
46
+
47
+ Alternatively, you can use ` git clone ` , which will download the entire repository.
48
+ To do so, clone the MetaMask SDK examples repository and navigate into the ` partners/dynamic ` directory:
107
49
108
50
``` bash
109
- git clone https://github.com/MetaMask/metamask-dynamic
51
+ git clone https://github.com/MetaMask/metamask-sdk-examples
52
+ cd metamask-sdk-examples/partners/dynamic
110
53
```
111
54
112
- 2. Navigate into the repository:
113
-
114
- ` ` ` bash
115
- cd metamask-dynamic
116
- ` ` `
55
+ < /div>
56
+ < /details>
117
57
118
58
3. Install dependencies:
119
59
120
- ` ` ` bash
121
- pnpm install
122
- ` ` `
60
+ ` ` ` bash
61
+ pnpm install
62
+ ` ` `
123
63
124
64
4. Create a ` .env.local` file:
125
65
126
- ` ` ` bash
127
- touch .env.local
128
- ` ` `
66
+ ` ` ` bash
67
+ touch .env.local
68
+ ` ` `
129
69
130
70
5. In ` .env.local` , add a ` NEXT_PUBLIC_DYNAMIC_ENVIRONMENT_ID` environment variable, replacing ` < YOUR-ENVIRONMENT-ID> ` with your Dynamic Environment ID:
131
71
132
- ` ` ` text title=" .env.local"
133
- NEXT_PUBLIC_DYNAMIC_ENVIRONMENT_ID=< YOUR-ENVIRONMENT-ID>
134
- ` ` `
72
+ ` ` ` text title=" .env.local"
73
+ NEXT_PUBLIC_DYNAMIC_ENVIRONMENT_ID=< YOUR-ENVIRONMENT-ID>
74
+ ` ` `
135
75
136
- 4 . Run the project:
76
+ 6 . Run the project:
137
77
138
- ` ` ` bash
139
- pnpm dev
140
- ` ` `
78
+ ` ` ` bash
79
+ pnpm dev
80
+ ` ` `
141
81
142
82
You' ve successfully set up MetaMask SDK and Dynamic SDK.
143
83
See how to [use the combined SDKs](#usage).
@@ -148,8 +88,8 @@ See how to [use the combined SDKs](#usage).
148
88
149
89
Install the SDK and the required dependencies to an existing project:
150
90
151
- ```bash
152
- pnpm i @dynamic-labs/sdk-react-core @dynamic-labs/ethereum @dynamic-labs/wagmi-connector wagmi viem @tanstack/react-query
91
+ ```bash npm2yarn
92
+ npm install @dynamic-labs/sdk-react-core @dynamic-labs/ethereum @dynamic-labs/wagmi-connector wagmi viem @tanstack/react-query
153
93
```
154
94
155
95
### 2. Configure providers
@@ -268,3 +208,7 @@ Common issues and solutions include:
268
208
- Test on actual mobile devices.
269
209
- Verify redirect URLs.
270
210
- Check MetaMask mobile app installation.
211
+
212
+ ## Live example
213
+
214
+ <iframe className="mt-6" width="100%" height="600px" frameBorder="0" src="https://stackblitz.com/github/MetaMask/metamask-sdk-examples/tree/main/partners/dynamic?ctl=1&embed=1&file=app%2Fproviders.tsx&hideNavigation=1"></iframe>
0 commit comments