Created
October 16, 2020 10:24
-
-
Save eerkaijun/f0e6bbd96329c54127b1c3e6b4489818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<v-app> | |
<v-card> | |
Some random content | |
</v-card> | |
</v-app> | |
</template> | |
<script language="javascript" type="text/javascript" src="jslibs/web3.min.js"></script> | |
<script> | |
export default { | |
name: 'App', | |
data () { | |
return { | |
web3Provider: null, | |
contract: null, | |
account: '0x0', | |
} | |
}, | |
async mounted() { | |
await this.initProvider(); | |
}, | |
methods: { | |
async initProvider() { | |
if (typeof web3 !== 'undefined') { | |
this.web3Provider = web3.currentProvider; | |
console.log(web3.currentProvider); | |
//ethereum.enable(); | |
web3 = new Web3(web3.currentProvider); | |
console.log(web3.version); | |
this.account = web3.eth.accounts[0]; | |
} else { | |
console.log("Please install Metamask to continue."); | |
} | |
setInterval(function() { | |
// Check if account has changed | |
if (web3.eth.accounts[0] !== this.account) { | |
this.account = web3.eth.accounts[0]; | |
alert("You changed account!"); | |
} | |
}, 100); | |
}, | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment