Skip to content

Instantly share code, notes, and snippets.

@eerkaijun
Created October 16, 2020 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eerkaijun/f0e6bbd96329c54127b1c3e6b4489818 to your computer and use it in GitHub Desktop.
Save eerkaijun/f0e6bbd96329c54127b1c3e6b4489818 to your computer and use it in GitHub Desktop.
<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