aboutsummaryrefslogtreecommitdiffstats
path: root/mascara/example/index.js
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2017-04-05 02:27:45 +0800
committerGitHub <noreply@github.com>2017-04-05 02:27:45 +0800
commit5d967eeebb9f3cf4c2d3fcfe0b74cf6e8440c3cb (patch)
tree38c3fac654c41df24f01b6de3aa453d68b259c07 /mascara/example/index.js
parent39181ed33f1b9829f82c44d2f21e2f3ab1d1c979 (diff)
parent4779999bfc7e03eedf3fd2702f7f448d751218f8 (diff)
downloadtangerine-wallet-browser-5d967eeebb9f3cf4c2d3fcfe0b74cf6e8440c3cb.tar.gz
tangerine-wallet-browser-5d967eeebb9f3cf4c2d3fcfe0b74cf6e8440c3cb.tar.zst
tangerine-wallet-browser-5d967eeebb9f3cf4c2d3fcfe0b74cf6e8440c3cb.zip
Merge pull request #1307 from MetaMask/mascara
Proof of Concept: Mascara
Diffstat (limited to 'mascara/example/index.js')
-rw-r--r--mascara/example/index.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/mascara/example/index.js b/mascara/example/index.js
new file mode 100644
index 000000000..aae7ccd19
--- /dev/null
+++ b/mascara/example/index.js
@@ -0,0 +1,57 @@
+window.addEventListener('load', web3Detect)
+window.addEventListener('message', console.warn)
+
+function web3Detect() {
+ if (global.web3) {
+ logToDom('web3 detected!')
+ startApp()
+ } else {
+ logToDom('no web3 detected!')
+ }
+}
+
+function startApp(){
+ console.log('app started')
+
+ var primaryAccount
+ console.log('getting main account...')
+ web3.eth.getAccounts((err, addresses) => {
+ if (err) console.error(err)
+ console.log('set address', addresses[0])
+ primaryAccount = addresses[0]
+ })
+
+ document.querySelector('.action-button-1').addEventListener('click', function(){
+ console.log('saw click')
+ console.log('sending tx')
+ primaryAccount
+ web3.eth.sendTransaction({
+ from: primaryAccount,
+ to: primaryAccount,
+ value: 0,
+ }, function(err, txHash){
+ if (err) throw err
+ console.log('sendTransaction result:', err || txHash)
+ })
+ })
+ document.querySelector('.action-button-2').addEventListener('click', function(){
+ console.log('saw click')
+ setTimeout(function(){
+ console.log('sending tx')
+ web3.eth.sendTransaction({
+ from: primaryAccount,
+ to: primaryAccount,
+ value: 0,
+ }, function(err, txHash){
+ if (err) throw err
+ console.log('sendTransaction result:', err || txHash)
+ })
+ })
+ })
+
+}
+
+function logToDom(message){
+ document.body.appendChild(document.createTextNode(message))
+ console.log(message)
+}