@@ -37,32 +37,68 @@ The build outputs `snap.manifest.json` alongside `dist/bundle.js`.
3737The snap now appears in the MetaMask Snaps list and can be invoked by dApps
3838using ` local:@ecency/snap ` .
3939
40+ ### Playground
41+
42+ For a quick way to install and interact with the snap locally, start the
43+ included playground which builds the snap and serves an example page:
44+
45+ ``` bash
46+ yarn workspace @ecency/snap-playground start
47+ ```
48+
49+ Open ` http://localhost:5173 ` in a MetaMask Flask-enabled browser and use the
50+ page buttons to install the snap, set a mnemonic and request derived addresses
51+ for all supported chains. The playground resolves any Hive account name on your
52+ behalf and shows the public keys returned by the snap.
53+
4054## Usage
4155
4256The snap exposes several RPC methods:
4357
4458- ` initialize ` – store a BIP39 mnemonic inside the snap.
4559- ` unlock ` – validate and unlock previously stored mnemonic.
46- - ` getAddress ` – return a public address for a given chain (` HIVE ` , ` BTC ` , ` ETH ` , etc.).
60+ - ` getAddresses ` – derive public keys for Hive roles and addresses for BTC,
61+ ETH, APT, TRX, ATOM and SOL. dApps can perform any Hive account lookups
62+ themselves using the returned keys.
4763- ` signHiveTx ` – sign a Hive transaction with the active key.
4864- ` signExternalTx ` – sign transactions for external chains via ` signExternalTx ` from
4965 ` @ecency/wallets ` .
5066- ` getBalance ` – query balances using ` useGetExternalWalletBalanceQuery ` (todo: integrate).
5167
52- Example from a dApp:
53-
54- ``` ts
55- const result = await window .ethereum .request ({
56- method: " wallet_invokeSnap" ,
57- params: {
58- snapId: " local:@ecency/snap" ,
59- request: {
60- method: " getAddress" ,
61- params: { chain: " HIVE" },
62- },
63- },
64- });
65- ```
68+ ### Connecting from a dApp
69+
70+ 1 . Request the snap to be installed in MetaMask. For local development use
71+ ` local:@ecency/snap ` ; when published to npm replace it with ` npm:@ecency/snap ` and an
72+ optional version range.
73+
74+ ``` ts
75+ await window .ethereum .request ({
76+ method: " wallet_enable" ,
77+ params: [{
78+ wallet_snap: {
79+ " local:@ecency/snap" : {}
80+ }
81+ }]
82+ });
83+ ```
84+
85+ 2 . Invoke RPC methods exposed by the snap:
86+
87+ ``` ts
88+ const result = await window .ethereum .request ({
89+ method: " wallet_invokeSnap" ,
90+ params: {
91+ snapId: " local:@ecency/snap" ,
92+ request: { method: " getAddresses" }
93+ }
94+ });
95+ // Optional: resolve Hive account name
96+ const account = await lookupHiveAccount (result .hive .active );
97+ ```
98+
99+ 3 . Use the returned data in your application. When integrating into Ecency.com, these
100+ calls can be wrapped in a connector module that detects MetaMask and manages snap
101+ installation.
66102
67103## Required Permissions
68104
@@ -82,10 +118,28 @@ stored in memory or exposed to the client.
82118
83119- Keys are derived only when required and cleared from memory immediately after
84120 use.
85- - No network requests are made.
121+ - No network requests are made by the snap itself .
86122- All transaction data is validated before processing.
87123- No sensitive data is stored in browser storage.
88124- The mnemonic phrase resides in the snap's managed state. Although snaps run in
89125 an isolated environment, that state persists on the user's machine. Avoid
90126 exposing the mnemonic and consider encrypting state for production
91127 deployments.
128+
129+ ## Publishing & Discovery
130+
131+ To prepare the snap for public use:
132+
133+ 1 . ** Build** the bundle and manifest:
134+
135+ ``` bash
136+ yarn workspace @ecency/snap build
137+ ```
138+
139+ 2 . ** Publish** the package to npm from ` packages/snap ` .
140+
141+ 3 . ** Submit** the npm package to the [ MetaMask Snaps Directory] ( https://docs.metamask.io/snaps/developing/register/ ) for
142+ listing and discovery.
143+
144+ Once published, dApps like Ecency.com can enable the snap using the ` npm:@ecency/snap `
145+ identifier in the ` wallet_enable ` request.
0 commit comments