aboutsummaryrefslogtreecommitdiffstats
path: root/mascara/example/app.js
blob: d0cb6ba83573aea4a43c299110b067d12c2d3b3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const EthQuery = require('ethjs-query')

window.addEventListener('load', loadProvider)
window.addEventListener('message', console.warn)

async function loadProvider() {
  const ethereumProvider = window.metamask.createDefaultProvider({ host: 'http://localhost:9001' })
  const ethQuery = new EthQuery(ethereumProvider)
  const accounts = await ethQuery.accounts()
  logToDom(accounts.length ? accounts[0] : 'LOCKED or undefined')
  setupButton(ethQuery)
}


function logToDom(message){
  document.getElementById('account').innerText = message
  console.log(message)
}

function setupButton (ethQuery) {
  const button = document.getElementById('action-button-1')
  button.addEventListener('click', async () => {
    const accounts = await ethQuery.accounts()
    logToDom(accounts.length ? accounts[0] : 'LOCKED or undefined')
  })
}