-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmessageBoard.html
More file actions
97 lines (93 loc) · 2.51 KB
/
messageBoard.html
File metadata and controls
97 lines (93 loc) · 2.51 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="js/web3.min.js"></script>
</head>
<body>
<h2>目前的留言內容是:<em id="message"></em></h2>
<input type="text" id="editMessage" placeholder="文字修改">
<input type="button" id="send" value="送出修改內容">
<script>
var web3 = new Web3(window.web3.currentProvider);
var Contract;
var abi = [
{
"constant": false,
"inputs": [
{
"name": "editMessage",
"type": "string"
}
],
"name": "editMessage",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"name": "initMessage",
"type": "string"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"constant": true,
"inputs": [],
"name": "message",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "viewMessage",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
var address = '0xeFd35a0c1b6B7dc083C290123f132C4A1477eBaA';
async function init(){
Contract = await new web3.eth.Contract(abi,address);
Contract.methods.viewMessage().call()
.then(function(data){
document.getElementById('message').textContent = data;
})
}
init();
async function send(){
var accounts = await web3.eth.getAccounts();
var str = document.getElementById('editMessage').value;
Contract.methods.editMessage(str)
.send({from:accounts[0]})
.then(function(data){
console.log(data);
})
}
document.getElementById('send').addEventListener('click',send);
</script>
</body>
</html>