2017-09-19 04:08:02 +02:00
|
|
|
const EthQuery = require('ethjs-query')
|
|
|
|
|
|
|
|
window.addEventListener('load', loadProvider)
|
2017-03-29 19:53:43 +02:00
|
|
|
window.addEventListener('message', console.warn)
|
2016-08-26 20:08:23 +02:00
|
|
|
|
2017-09-19 04:08:02 +02:00
|
|
|
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)
|
2016-08-26 20:08:23 +02:00
|
|
|
}
|
|
|
|
|
2016-09-13 03:30:45 +02:00
|
|
|
|
|
|
|
function logToDom(message){
|
2017-09-19 04:08:02 +02:00
|
|
|
document.getElementById('account').innerText = message
|
2016-09-13 03:30:45 +02:00
|
|
|
console.log(message)
|
2017-03-29 03:02:08 +02:00
|
|
|
}
|
2017-09-19 04:08:02 +02:00
|
|
|
|
|
|
|
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')
|
|
|
|
})
|
|
|
|
}
|