-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
91 lines (78 loc) · 2.46 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Smart Contract</title>
<script src="./node_modules/web3/dist/web3.js"></script>
</head>
<body>
<input type="text" name="input" id="input" placeholder="Enter Name">
<button id="button">Set Name</button>
<pre id="output"></pre>
<script>
var web3;
if (typeof web3 !== "undefined") {
web3 = new Web3(web3.currentProvider)
}
else {
web3 = new Web3(new Web3.providers.HttpProvider("https//:localhost:8545"))
}
web3.eth.defaultAccount = web3.eth.accounts[0];
abi = [
{
"constant": false,
"inputs": [
{
"name": "_name",
"type": "string"
}
],
"name": "setName",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getName",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
var contract = new web3.eth.Contract(abi, "0xE5dac31337bdA31b1039f1597F0E5b963bA2E1c5")
console.log(contract)
var output = document.getElementById("output")
var input = document.getElementById("input")
var button = document.getElementById("button")
button.addEventListener("click", function () {
contract.methods.setName(input.value)
console.log(contract.methods.getName())
output.innerText = contract.methods.getName()
})
</script>
</body>
</html>