@@ -9,10 +9,8 @@ import TabItem from "@theme/TabItem";
99
1010# Connect to MetaMask using JavaScript
1111
12- Get started with [ MetaMask SDK] ( https://github.com/MetaMask/metamask-sdk ) in your JavaScript dapp. You can set up the SDK in the following ways:
13-
14- - [ Quickstart template] ( #set-up-using-a-template ) - Clone the template to set up a JavaScript dapp.
15- - [ Manual setup] ( #set-up-manually ) - Set up MetaMask SDK in an existing dapp.
12+ Get started with MetaMask SDK in your JavaScript dapp.
13+ You can [ download the quickstart template] ( #set-up-using-a-template ) or [ manually set up the SDK] ( #set-up-manually ) in an existing dapp.
1614
1715<p align =" center " >
1816 <a href =" https://metamask-javascript-demo.vercel.app/ " target =" _blank " >
@@ -34,25 +32,25 @@ Get started with [MetaMask SDK](https://github.com/MetaMask/metamask-sdk) in you
3432 npx degit MetaMask/metamask-sdk-examples/quickstarts/javascript metamask-javascript
3533 ```
3634
37- > ` degit ` is a tool that enables cloning only the directory structure from a GitHub repository, without retrieving the entire repository.
38-
39352 . Navigate into the repository:
4036
4137 ``` bash
4238 cd metamask-javascript
4339 ```
4440
4541 <details >
46- <summary >GitHub clone instead of degit? </summary >
42+ <summary >Degit vs. Git clone </summary >
4743 <div >
48- Clone the MetaMask SDK examples repository and navigate into the ` quickstarts/javascript ` directory:
4944
50- ``` bash
51- git clone https://github.com/MetaMask/metamask-sdk-examples
52- cd metamask-sdk-examples/quickstarts/javascript
53- ```
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 ` quickstarts/javascript ` directory:
5449
55- > Note: _ this will download the entire repository._
50+ ``` bash
51+ git clone https://github.com/MetaMask/metamask-sdk-examples
52+ cd metamask-sdk-examples/quickstarts/javascript
53+ ```
5654
5755 < /div>
5856 < /details>
@@ -89,11 +87,11 @@ The following are examples of using the SDK in various JavaScript environments:
8987<TabItem value="Web dapps">
9088
9189```javascript
92- import { MetaMaskSDK } from ' @metamask/sdk'
90+ import { MetaMaskSDK } from " @metamask/sdk"
9391
9492const MMSDK = new MetaMaskSDK({
9593 dappMetadata: {
96- name: ' Example JavaScript dapp' ,
94+ name: " Example JavaScript dapp" ,
9795 url: window.location.href,
9896 // iconUrl: "https://mydapp.com/icon.png" // Optional
9997 },
@@ -110,7 +108,7 @@ const MMSDK = new MetaMaskSDK({
110108 <script>
111109 const MMSDK = new MetaMaskSDK.MetaMaskSDK({
112110 dappMetadata: {
113- name: ' Example JavaScript dapp' ,
111+ name: " Example JavaScript dapp" ,
114112 url: window.location.href,
115113 // iconUrl: "https://mydapp.com/icon.png" // Optional
116114 },
@@ -137,13 +135,13 @@ Connect to MetaMask and get the provider for RPC requests:
137135const provider = MMSDK.getProvider ()
138136
139137const accounts = await MMSDK.connect ()
140- console .log (' Connected account:' , accounts[0 ])
138+ console.log(" Connected account:" , accounts[0])
141139
142140const result = await provider.request({
143- method: ' eth_accounts' ,
141+ method: " eth_accounts" ,
144142 params: [],
145143})
146- console .log (' eth_accounts result:' , result)
144+ console.log(" eth_accounts result:" , result)
147145` ` `
148146
149147`MMSDK.connect ()` handles cross-platform connection (desktop and mobile), including deeplinking.
@@ -155,7 +153,7 @@ Use `provider.request()` for arbitrary [JSON-RPC requests](/wallet/reference/jso
155153| Method | Description |
156154| --------------------------------------------------------------------------------- | -------------------------------------------------------- |
157155| [` connect()` ](../reference/sdk-methods.md#connect) | Triggers wallet connection flow |
158- | [ ` connectAndSign({ msg: ' ...' }) ` ] ( ../reference/sdk-methods.md#connectandsign ) | Connects and prompts user to sign a message |
156+ | [` connectAndSign({ msg: " ..." })` ](../reference/sdk-methods.md#connectandsign) | Connects and prompts user to sign a message |
159157| [` getProvider()` ](../reference/sdk-methods.md#getprovider) | Returns the provider object for RPC requests |
160158| [` provider.request({ method, params })` ](/wallet/reference/provider-api/# request) | Calls any Ethereum JSON‑RPC method |
161159| [Batched RPC](../guides/batch-requests.md) | Use ` metamask_batch` to group multiple JSON-RPC requests |
@@ -168,22 +166,22 @@ const accounts = await MMSDK.connect()
168166
169167// 2. Connect and sign in one step
170168const signResult = await MMSDK.connectAndSign({
171- msg: ' Sign in to Dapp ' ,
169+ msg: " Sign in to the dapp " ,
172170})
173171
174172// 3. Get provider for RPC requests
175173const provider = MMSDK.getProvider ()
176174
177175// 4. Make an RPC request
178176const result = await provider.request({
179- method: ' eth_accounts' ,
177+ method: " eth_accounts" ,
180178 params: [],
181179})
182180
183181// 5. Batch multiple RPC requests
184182const batchResults = await provider.request({
185- method: ' metamask_batch' ,
186- params: [{ method: ' eth_accounts' }, { method: ' eth_chainId' }],
183+ method: " metamask_batch" ,
184+ params: [{ method: " eth_accounts" }, { method: " eth_chainId" }],
187185})
188186` ` `
189187
0 commit comments