@@ -31,52 +31,58 @@ starter kit by running:
31
31
yarn create @metamask/snap gas-estimation-snap
32
32
```
33
33
34
- or
35
-
36
- ``` bash
37
- npx @metamask/create-snap gas-estimation-snap
38
- ```
39
-
40
- or
41
-
42
- ``` bash
43
- npm create @metamask/snap gas-estimation-snap
44
- ```
45
-
46
34
Next, ` cd ` into the ` gas-estimation-snap ` project directory and run:
47
35
48
36
``` bash
49
37
yarn install
50
38
```
51
39
52
- This initializes your development environment with the required dependencies.
53
- You may get a warning similar to the following:
40
+ This initializes your development environment with the required dependencies.
41
+
42
+ <details >
43
+ <summary >Did you get a warning?</summary >
44
+ <div >
45
+ You may get a warning such as:
54
46
55
47
``` bash
56
48
@lavamoat/allow-scripts has detected dependencies without configuration. explicit configuration required.
57
49
run " allow-scripts auto" to automatically populate the configuration.
58
50
```
59
-
60
- You can resolve this error by running the following command:
61
-
51
+ You can resolve this error by running:
52
+
62
53
``` bash
63
54
yarn run allow-scripts auto
64
55
```
56
+ </div >
57
+ </details >
58
+
59
+
60
+ ### 2. (Optional) Customize your Snap's UX
61
+
62
+ This Snap is generated from a TypeScript template Snap. We recommend customizing your
63
+ Snap to improve its UX, but this is optional for testing. If you don't wish to customize your Snap,
64
+ skip to [ Step 3] ( #3-enable-network-access ) .
65
65
66
- ### 2. Add a custom icon
66
+ #### 2.1. Provide an icon
67
67
68
- Your Snap must [ display an icon] ( ../best-practices/design-guidelines.md#optimize-your-metadata ) in MetaMask.
69
- To add an icon, create a new folder ` images ` in the Snap package ` packages/snap/ ` :
68
+ [ Optimize your metadata] ( ../best-practices/design-guidelines.md#optimize-your-metadata ) and display an icon for your Snap in MetaMask.
69
+
70
+ Create a new folder ` images ` in the Snap package ` packages/snap/ ` :
70
71
71
72
``` bash
72
73
mkdir packages/snap/images
73
74
```
74
75
75
76
Download
76
77
[ this ` gas.svg ` icon file] ( https://raw.githubusercontent.com/Montoya/gas-fee-snap/main/packages/snap/images/gas.svg )
77
- into the ` ìmages ` folder you just created.
78
- This is a free icon, "Gas" by Mello from
79
- [ Noun Project] ( https://thenounproject.com/browse/icons/term/gas/ ) .
78
+ into that ` ìmages ` folder.
79
+
80
+ <details >
81
+ <summary >Icon attribution</summary >
82
+ <div >
83
+ This is a free icon, "Gas" by Mello from the [ Noun Project] ( https://thenounproject.com/browse/icons/term/gas/ ) .
84
+ </div >
85
+ </details >
80
86
81
87
Your file structure should look like this:
82
88
@@ -102,10 +108,9 @@ gas-estimation-snap/
102
108
├─ ... (other stuff)
103
109
```
104
110
105
- Open ` packages/snap/snap.manifest.json ` in a text editor.
106
- This file contains the main configuration details for your Snap.
107
- Edit the ` npm ` object, within the ` location ` object,
108
- and add ` iconPath ` with the value ` "images/gas.svg" ` to point to your new icon:
111
+ Open ` packages/snap/snap.manifest.json ` in a text editor. This file contains the main configuration
112
+ details for your Snap. Edit the ` npm ` object, within the ` location ` object, and add ` iconPath ` with
113
+ the value ` "images/gas.svg" ` to point to your new icon:
109
114
110
115
``` json title="snap.manifest.json"
111
116
"location" : {
@@ -118,8 +123,8 @@ and add `iconPath` with the value `"images/gas.svg"` to point to your new icon:
118
123
}
119
124
```
120
125
121
- Open ` packages/snap/package.json ` in a text editor.
122
- Edit the ` files ` array and add the ` images/ ` folder:
126
+ Open ` packages/snap/package.json ` in a text editor. Edit the ` files ` array and reference the
127
+ ` images/ ` folder:
123
128
124
129
``` json title="package.json"
125
130
"files" : [
@@ -129,6 +134,39 @@ Edit the `files` array and add the `images/` folder:
129
134
],
130
135
```
131
136
137
+ #### 2.2. Update your Snap's name
138
+
139
+ [ Optimize your metadata] ( ../best-practices/design-guidelines.md#optimize-your-metadata ) and update
140
+ your Snap's name in MetaMask.
141
+ MetaMask uses the ` proposedName ` of the Snap, currently "TypeScript Example" in the template.
142
+
143
+ Open ` packages/snap/snap.manifest.json ` in a text editor.
144
+ Edit the ` "proposedName" ` property within the metadata to provide a functional name such as
145
+ "Gas Estimator":
146
+
147
+ ``` json title="snap.manifest.json"
148
+ {
149
+ "version" : " 0.1.0" ,
150
+ "description" : " An example Snap written in TypeScript." ,
151
+ "proposedName" : " Gas Estimator" ,
152
+ ...
153
+ }
154
+ ```
155
+
156
+ #### 2.3. Update your Snap's button
157
+
158
+ Open ` packages/site/src/components/Buttons.tsx ` in a text editor.
159
+ Edit the ` Button ` property to provide functional label text such as "Estimate Gas":
160
+
161
+ ``` typescript title="Buttons.tsx"
162
+ export const SendHelloButton = (props : ComponentProps <typeof Button >) => {
163
+ return <Button {... props }>Estimate Gas < / Button > ;
164
+ };
165
+ ````
166
+
167
+ These three updates are the minimum required to ensure that each user interaction with your Snap is well - informed .
168
+ However , your Snap will function without these tweaks.
169
+
132
170
### 3. Enable network access
133
171
134
172
To enable your Snap to [access the internet using the ` fetch ` API ](../ ../ features / network - access .md ),
@@ -144,7 +182,6 @@ permission in `packages/snap/snap.manifest.json`:
144
182
},
145
183
"endowment:network-access": {}
146
184
},
147
- "manifestVersion" : " 0.1"
148
185
` ` `
149
186
150
187
### 4. Fetch gas fee estimates
@@ -187,7 +224,7 @@ Update the `hello` method with the following code:
187
224
case " hello" :
188
225
const fees = await getFees ();
189
226
return snap .request ({
190
- method: ' snap_dialog' ,
227
+ method: " snap_dialog" ,
191
228
params: {
192
229
type: " alert" ,
193
230
content : (
@@ -208,7 +245,7 @@ case "hello":
208
245
case " hello" :
209
246
const fees = await getFees ();
210
247
return snap .request ({
211
- method: ' snap_dialog' ,
248
+ method: " snap_dialog" ,
212
249
params: {
213
250
type: " alert" ,
214
251
content: panel ([
@@ -223,72 +260,73 @@ case "hello":
223
260
</TabItem>
224
261
</Tabs>
225
262
226
- ### 5. Build and test the Snap
263
+ ### 5. Build and test your Snap
227
264
228
- To build and test your Snap:
265
+ Complete the following steps to build and test your Snap:
229
266
230
- 1 . Open ` package.json ` in the root directory of the project, and increment the ` "version" ` (if the ` "version" ` is
231
- ` 0.1.0 ` , increase it to ` 0.2.0 ` ).
267
+ #### 5.1. Build your Snap
232
268
233
- 2 . From the command line, run ` yarn start ` .
234
- In the terminal, at the bottom of the message log, you see the browser URL:
269
+ From the command line, run ` yarn start ` .
270
+ The following displays:
271
+
272
+ ` ` ` bash
273
+ You can now view site in the browser .
235
274
236
- ``` bash
237
- You can now view site in the browser.
275
+ http : // localhost:8000/
276
+ ` ` `
238
277
239
- http://localhost:8000/
240
- ```
278
+ Open [ ` localhost : 8000 ` ]( http://localhost:8000/) in your browser (with MetaMask Flask installed).
279
+ A page like the following displays:
241
280
242
- 3 . Open [ ` localhost:8000 ` ] ( http://localhost:8000/ ) in your browser (with MetaMask Flask installed).
243
- A page like the following displays:
281
+ <img src={require('../../assets/template-snap.png').default} alt="Test dapp with template Snap" style={{border: '1px solid #DCDCDC'}} />
244
282
245
- <img src={require('../../assets/ template-snap.png').default} alt="Test dapp with template Snap" style={{border: '1px solid #DCDCDC'}} />
283
+ This is a template test dapp for installing and testing your Snap.
246
284
247
- This is a boilerplate test dapp for installing and testing your Snap.
285
+ #### 5.2. Test your Snap
248
286
249
- 4 . Select ** Connect** to connect Flask to the dapp.
250
- After connecting, you're prompted to install the Snap with the following permissions:
287
+ Select **Connect** to connect Flask to the dapp.
288
+ After connecting, you're prompted to install the Snap with the following permissions:
251
289
252
- - ** Allow dapps to communicate directly with this Snap.**
253
- - ** Access the internet.**
254
- - ** Display dialog windows in MetaMask.**
290
+ - **Allow websites to communicate directly with this Snap.**
291
+ - **Access the internet.**
292
+ - **Display dialog windows in MetaMask.**
255
293
256
- 5 . Select ** Approve ** > ** Install ** .
294
+ Next, select **Confirm ** > **OK **.
257
295
258
- 6 . After installing, the ** Send message** button on the page is enabled. Select this button . A dialog prompt displays with the response from the gas fee API:
296
+ Select the **Send message** button (or **Estimate gas** button, if you followed Step 2) . A dialog prompt displays with the response from the gas fee API:
259
297
260
298
<p align="center">
261
299
<img src={require('../../assets/gas-estimation.png').default} alt="Gas estimation dialog" width="400px" style={{border: '1px solid #DCDCDC'}} />
262
300
</p>
263
301
264
- You have integrated a public API into MetaMask and displayed real-time gas fee estimates.
265
-
266
- ### 6. Next steps
302
+ Congratulations, you have integrated a public API into MetaMask and displayed real-time gas fee estimates.
267
303
268
- Next, you can try:
304
+ ### Next steps
269
305
306
+ You can improve your Snap's UX by:
307
+ - Completing [Step 2](#2-optional-customize-your-snaps-ux).
270
308
- Parsing the JSON response from the remote API.
271
- - Displaying the fees in a nicely formatted way .
309
+ - Formatting the fees for better readability .
272
310
273
- You can also update the fields in ` snap.manifest.json ` to match your custom Snap:
311
+ Before publishing a Snap, it's also important to customize the metadata and properties of your Snap:
274
312
275
- - ` proposedName ` - The name of your Snap.
276
- - ` description ` - The description of your Snap.
277
- - ` source ` - The ` shasum ` is set automatically when you build from the command line.
278
- If you decided to publish your Snap to ` npm ` , update the ` location ` to its published location.
313
+ - Update the ` location ` in ` snap .manifest .json ` to your Snap's published location.
314
+ - Update the ` description ` in ` snap .manifest .json ` to a description of your Snap.
315
+ - Update the ` name ` , ` version ` , ` description ` , and ` repository ` fields of
316
+ ` / packages / snap / package .json ` (even if you do not plan to publish your Snap to npm).
317
+ - Update the content of ` / packages / site / src / pages / index .tsx ` by changing the
318
+ name of the method for showing gas fee estimates. If you change the method name in
319
+ ` / packages / site / src / pages / index .tsx ` , ensure you change the method name in
320
+ ` / packages / snap / src / index .ts ` to match.
279
321
280
- Similarly, you should update the ` name ` , ` version ` , ` description ` , and ` repository ` fields of
281
- ` /packages/snap/package.json ` even if you do not plan to publish your Snap to npm.
322
+ :::note
323
+ When editing ` source ` , the ` shasum ` is set automatically when you build from the command line.
324
+ :::
282
325
283
326
:::caution important
284
327
The ` version ` and ` repository ` fields in ` snap .manifest .json ` inherit the values from
285
328
` package .json ` and overwrite them in ` snap .manifest .json ` .
286
- We recommend updating ` version ` and ` repository ` in ` package.json ` first, then building the Snap project.
329
+ We recommend updating ` version ` and ` repository ` in ` package .json ` first, then building your Snap project.
287
330
:::
288
331
289
- You can update the content of ` /packages/site/src/pages/index.tsx ` by changing the
290
- name of the method for showing gas fee estimates.
291
- If you change the method name in ` /packages/site/src/pages/index.tsx ` , ensure you change the method name in ` /packages/snap/src/index.ts ` to match.
292
-
293
- After you have made all necessary changes, you can
294
- [ publish your Snap to npm] ( ../../how-to/publish-a-snap.md ) .
332
+ After you have made all necessary changes, you can [publish your Snap to npm](../../how-to/publish-a-snap.md).
0 commit comments