1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 08:09:15 +01:00
metamask-extension/mascara/example/app.js
2017-09-18 19:08:02 -07:00

26 lines
833 B
JavaScript

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')
})
}