A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/mascara/example/app.js

58 lines
1.4 KiB

window.addEventListener('load', web3Detect)
window.addEventListener('message', console.warn)
function web3Detect() {
if (global.web3) {
logToDom('web3 detected!')
8 years ago
startApp()
} else {
logToDom('no web3 detected!')
}
}
function startApp(){
console.log('app started')
var primaryAccount
8 years ago
console.log('getting main account...')
web3.eth.getAccounts((err, addresses) => {
if (err) console.error(err)
console.log('set address', addresses[0])
8 years ago
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)
}