diff options
library - popup handler demo
Diffstat (limited to 'library/example')
-rw-r--r-- | library/example/README.md | 5 | ||||
-rw-r--r-- | library/example/index.html | 17 | ||||
-rw-r--r-- | library/example/index.js | 42 |
3 files changed, 64 insertions, 0 deletions
diff --git a/library/example/README.md b/library/example/README.md new file mode 100644 index 000000000..2a5a1cce0 --- /dev/null +++ b/library/example/README.md @@ -0,0 +1,5 @@ +``` +trap 'kill %1' SIGINT +beefy frame.js:bundle.js 9001 --live & \ +beefy example/index.js:bundle.js index.js:zero.js --cwd example/ 9002 --live --open +```
\ No newline at end of file diff --git a/library/example/index.html b/library/example/index.html new file mode 100644 index 000000000..aa15a4523 --- /dev/null +++ b/library/example/index.html @@ -0,0 +1,17 @@ +<!doctype html> + +<html lang="en"> +<head> + <meta charset="utf-8"> + + <title>MetaMask ZeroClient Example</title> + +</head> + +<body> + <button class="action-button-1">SYNC TX</button> + <button class="action-button-2">ASYNC TX</button> + <script src="./zero.js"></script> + <script src="./bundle.js"></script> +</body> +</html>
\ No newline at end of file diff --git a/library/example/index.js b/library/example/index.js new file mode 100644 index 000000000..d24c26f87 --- /dev/null +++ b/library/example/index.js @@ -0,0 +1,42 @@ + +window.addEventListener('load', web3Detect) + +function web3Detect() { + if (global.web3) { + document.body.innerHTML += 'web3 detected!' + } else { + document.body.innerHTML += 'no web3 detected!' + } + startApp() +} + +var primaryAccount = null +web3.eth.getAccounts(function(err, addresses){ + if (err) throw err + primaryAccount = addresses[0] +}) + + +function startApp(){ + document.querySelector('.action-button-1').addEventListener('click', function(){ + web3.eth.sendTransaction({ + from: primaryAccount, + value: 0, + }, function(err, txHash){ + if (err) throw err + console.log('sendTransaction result:', err || txHash) + }) + }) + document.querySelector('.action-button-2').addEventListener('click', function(){ + setTimeout(function(){ + web3.eth.sendTransaction({ + from: primaryAccount, + value: 0, + }, function(err, txHash){ + if (err) throw err + console.log('sendTransaction result:', err || txHash) + }) + }) + }) + +} |