22sidebar_label : Dynamic SDK
33description : Quickstart guide for using MetaMask SDK and Dynamic SDK.
44toc_max_heading_level : 2
5- keywords : [connect, MetaMask, Dynamic, SDK, dapp]
5+ keywords : [connect, MetaMask, Dynamic, SDK, dapp, Wallet SDK ]
66---
77
88# Connect to MetaMask using Dynamic SDK
99
1010Get started with MetaMask SDK and [ Dynamic SDK] ( https://docs.dynamic.xyz/introduction/welcome ) .
1111You 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.
3613
3714<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 >
3918</p >
4019
4120## Prerequisites
4221
4322- [ 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/ ) .
4624- [ MetaMask] ( https://metamask.io/ ) installed in your browser or on mobile.
4725- A [ Dynamic Environment ID] ( https://app.dynamic.xyz/ ) .
4826
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
8628
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 ) :
9330
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+ ```
9634
97- ```bash
98- pnpm run dev
99- ```
35+ 2 . Navigate into the repository:
10036
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+ ```
10340
104- # # Set up using a template
41+ <details >
42+ <summary >Degit vs. Git clone</summary >
43+ <div >
10544
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:
10749
10850 ``` 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
11053 ```
11154
112- 2. Navigate into the repository:
113-
114- ` ` ` bash
115- cd metamask-dynamic
116- ` ` `
55+ < /div>
56+ < /details>
11757
118583. Install dependencies:
11959
120- ` ` ` bash
121- pnpm install
122- ` ` `
60+ ` ` ` bash
61+ pnpm install
62+ ` ` `
12363
124644. Create a ` .env.local` file:
12565
126- ` ` ` bash
127- touch .env.local
128- ` ` `
66+ ` ` ` bash
67+ touch .env.local
68+ ` ` `
12969
130705. In ` .env.local` , add a ` NEXT_PUBLIC_DYNAMIC_ENVIRONMENT_ID` environment variable, replacing ` < YOUR-ENVIRONMENT-ID> ` with your Dynamic Environment ID:
13171
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+ ` ` `
13575
136- 4 . Run the project:
76+ 6 . Run the project:
13777
138- ` ` ` bash
139- pnpm dev
140- ` ` `
78+ ` ` ` bash
79+ pnpm dev
80+ ` ` `
14181
14282You' ve successfully set up MetaMask SDK and Dynamic SDK.
14383See how to [use the combined SDKs](#usage).
@@ -148,8 +88,8 @@ See how to [use the combined SDKs](#usage).
14888
14989Install the SDK and the required dependencies to an existing project:
15090
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
15393```
15494
15595### 2. Configure providers
@@ -268,3 +208,7 @@ Common issues and solutions include:
268208 - Test on actual mobile devices.
269209 - Verify redirect URLs.
270210 - 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