Skip to content
This repository was archived by the owner on Mar 21, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 32 additions & 23 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!doctype html>
<!DOCTYPE html>
<html>
<head>
<title>Hello, Snaps!</title>
<link rel="icon" type="image/svg" href="./images/icon.svg"/>
<link rel="icon" type="image/svg" href="./images/icon.svg" />
</head>

<body>
Expand All @@ -14,15 +14,18 @@ <h1>Hello, Snaps!</h1>
<li>Please note that:</li>
<ul>
<li>
The <code>snap.manifest.json</code> and <code>package.json</code> must be located in the server root directory..
The <code>snap.manifest.json</code> and
<code>package.json</code> must be located in the server root
directory..
</li>
<li>
The Snap bundle must be hosted at the location specified by the <code>location</code> field of <code>snap.manifest.json</code>.
The Snap bundle must be hosted at the location specified by the
<code>location</code> field of <code>snap.manifest.json</code>.
</li>
</ul>
</ul>
</details>
<br/>
<br />

<button class="connect">Connect</button>
<button class="sendHello">Send Hello</button>
Expand All @@ -31,34 +34,40 @@ <h1>Hello, Snaps!</h1>
<script>
const snapId = `local:${window.location.href}`;

const connectButton = document.querySelector('button.connect')
const sendButton = document.querySelector('button.sendHello')
const connectButton = document.querySelector('button.connect');
const sendButton = document.querySelector('button.sendHello');

connectButton.addEventListener('click', connect)
sendButton.addEventListener('click', send)
connectButton.addEventListener('click', connect);
sendButton.addEventListener('click', send);

// here we get permissions to interact with and install the snap
async function connect () {
await ethereum.request({
method: 'wallet_enable',
params: [{
wallet_snap: { [snapId]: {} },
}]
})
async function connect() {
let params = {};
await window.ethereum.request({
method: 'wallet_requestSnaps',
params: {
[snapId]: {
...params,
},
},
});
}

// here we call the snap's "hello" method
async function send () {
async function send() {
try {
const response = await ethereum.request({
method: 'wallet_invokeSnap',
params: [snapId, {
method: 'hello'
}]
})
params: {
snapId,
request: {
method: 'hello',
},
},
});
} catch (err) {
console.error(err)
alert('Problem happened: ' + err.message || err)
console.error(err);
alert('Problem happened: ' + err.message || err);
}
}
</script>
Expand Down
10 changes: 7 additions & 3 deletions snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "0.7.0",
"proposedName": "MetaMask Template Snap",
"description": "A MetaMask Snap template.",
"proposedName": "MetaMask Template Snap",
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/snap-template.git"
},
"source": {
"shasum": "W4FN/2A1mQSjjrO95MGptw7pr+UR8913AOIksoajQSo=",
"shasum": "szkOOEsBYIKpPnglTb+pEMXXoW1tKoZOjLTGgr3aJ8I=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand All @@ -18,7 +18,11 @@
}
},
"initialPermissions": {
"snap_confirm": {}
"snap_confirm": {},
"endowment:rpc": {
"dapps": true,
"snaps": false
}
},
"manifestVersion": "0.1"
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports.onRpcRequest = async ({ origin, request }) => {
switch (request.method) {
case 'hello':
return wallet.request({
return snap.request({
method: 'snap_confirm',
params: [
{
Expand Down