-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·164 lines (152 loc) · 4.41 KB
/
index.html
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>sbbs test</title>
<!-- Include web3.js here -->
<script language="javascript" type="text/javascript" src="web3.min.js"></script>
</head>
<body>
<script>
var sbbs;
var web3js = new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:9545"));
var abi = [
{
"inputs": [
{
"internalType": "string",
"name": "postData",
"type": "string"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "author",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "replyToAddress",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "postID",
"type": "uint256"
},
{
"indexed": false,
"internalType": "string",
"name": "postData",
"type": "string"
}
],
"name": "posted",
"type": "event"
},
{
"inputs": [],
"name": "getPostCount",
"outputs": [
{
"internalType": "uint256",
"name": "count",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function",
"constant": true
},
{
"inputs": [
{
"internalType": "uint256",
"name": "postID",
"type": "uint256"
}
],
"name": "getPost",
"outputs": [
{
"internalType": "address",
"name": "author",
"type": "address"
},
{
"internalType": "uint256",
"name": "replyTo",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "time",
"type": "uint256"
},
{
"internalType": "string",
"name": "postData",
"type": "string"
}
],
"stateMutability": "view",
"type": "function",
"constant": true
},
{
"inputs": [
{
"internalType": "uint256",
"name": "replyTo",
"type": "uint256"
},
{
"internalType": "string",
"name": "postData",
"type": "string"
}
],
"name": "createPost",
"outputs": [
{
"internalType": "uint256",
"name": "postID",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
];
var addr = "0xba11768D4a822a1648DDE372A6D5738311dC02a3";
sbbs = new web3js.eth.Contract(abi, addr);
function getPostCount() {
sbbs.methods.getPostCount().call()
.then(console.log);
}
function getPost() {
// var id = document.getElementById('postid');
sbbs.methods.getPost(1).call()
.then(console.log);
}
function createPost() {
var replyTo = 0;
var postData = "hello";
sbbs.methods.createPost(replyTo, postData).send({from:'0xf31D0681d065809a6B9CdF9eABd8Db7a10a14CaA'})
.on("receipt", console.log);
}
</script>
<button type="button" onclick="getPostCount()">getCount</button><br>
<button type="button" onclick="getPost()">getPost</button><br>
<button type="button" onclick="createPost()">createPost</button><br>
</body>
</html>