-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (70 loc) · 1.76 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
console.log('window.web3', window.web3)
console.log('window.ethereum', window.ethereum)
if (window.web3) {
console.log('1번입니다')
console.log(window.web3)
web3.web3Provider = window.ethereum
// try {
// window.ethereum.enable()
// } catch (error) {
// console.error("User denied~~~")
// }
} else {
console.log('2번입니다')
window.web3 = new Web3('http://localhost:8545')
web3.web3Provider = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
}
web3 = new Web3(web3.web3Provider)
console.log('web3 log', web3)
web3.eth.getChainId().then((data) => {
console.log('chain ID: ', data)
})
new Vue({
el: '#app',
vuetify: new Vuetify(),
data() {
return {
hello: '안녕하세요',
myAccounts: [],
myBalance: null,
receiveAccount: '',
balance: '',
receipt: null,
recbool: false,
selectedAccount: null,
sendEth: '',
}
},
async created() {
await web3.eth.getAccounts().then((data) => {
this.myAccounts = data
this.selectedAccount = data[0]
})
},
methods: {
async getAccounts() {
await web3.eth.getAccounts().then((data) => {
this.myAccounts = data
})
},
async getBalance() {
const weibalance = await web3.eth.getBalance(this.selectedAccount)
const getEth = await web3.utils.fromWei(weibalance)
this.myBalance = getEth
},
async sendBalance() {
const toWeiEth = await web3.utils.toWei(this.sendEth)
await web3.eth
.sendTransaction({
from: this.selectedAccount,
to: this.receiveAccount,
value: toWeiEth,
})
.then((receipt) => {
this.receipt = receipt
})
this.recbool = true
this.getBalance()
},
},
})