-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnameregistry.html
175 lines (152 loc) · 5.77 KB
/
nameregistry.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
165
166
167
168
169
170
171
172
173
174
175
<html>
<head>
<script src='web3.min.js'></script>
<script type="text/javascript" src="abilist.js"> </script>
<script type="text/javascript">
var accounts;
var contractInstance = null;
var resultbox;
window.addEventListener('load', nameregistry);
async function nameregistry() {
if (window.ethereum) {
window.web3 = new Web3(window.ethereum);
window.accounts = await ethereum.request({ method: 'eth_requestAccounts' });
var address = "0x322b3b22bCAB6701BCfEFd5986a76eC204A0B7bb";
contractInstance = await new window.web3.eth.Contract(nameregistryabi, address);
// Legacy dapp browsers...
} else if (window.web3) {
window.web3 = new Web3(web3.currentProvider);
// Acccounts always exposed
// web3.eth.sendTransaction({/* ... */});
}
// Non-dapp browsers...
else {
console.log('Non-Ethereum browser detected. You should consider trying MetaMask!');
window.web3 = null
}
addEvtHandlers();
}
function addEvtHandlers() {
let btn = document.getElementById("changeOwner");
btn.addEventListener('click', setattribute);
btn = document.getElementById("setAddr");
btn.addEventListener('click', setAddr);
btn = document.getElementById("setDescription");
btn.addEventListener('click', setattribute);
btn = document.getElementById("register");
btn.addEventListener('click', setoneval);
btn = document.getElementById("unregister");
btn.addEventListener('click', setoneval);
btn = document.getElementById("contracts");
btn.addEventListener('click', oneargfunc);
btn = document.getElementById("getAddr");
btn.addEventListener('click', oneargfunc);
btn = document.getElementById("getDescription");
btn.addEventListener('click', oneargfunc);
btn = document.getElementById("getOwner");
btn.addEventListener('click', oneargfunc);
btn = document.getElementById("numContracts");
btn.addEventListener('click', showvalues);
resultbox = document.getElementById("resultbox");
}
async function setattribute() {
if (contractInstance != null) {
try {
let conname = document.getElementById("conname");
let name = conname.value;
let conattr = document.getElementById("conattr");
let attr = conattr.value;
const value = await contractInstance.methods[this.id](name, attr).send({ from: accounts[0] });
resultbox.innerHTML = value;
} catch (error) {
resultbox.innerHTML = "error occured";
console.log(error);
}
}
}
async function setAddr() {
if (contractInstance != null) {
try {
let conname = document.getElementById("conname");
let name = conname.value;
let conattr = document.getElementById("conattr");
let address = web3.utils.toChecksumAddress(conattr.value);
const value = await contractInstance.methods.setAddr(name, address).send({ from: accounts[0] });
resultbox.innerHTML = value;
} catch (error) {
resultbox.innerHTML = "error occured";
console.log(error);
}
}
}
async function setoneval() {
if (contractInstance != null) {
try {
let conname = document.getElementById("conname");
let name = conname.value;
let value = await contractInstance.methods[this.id](name).send({ from: accounts[0] });
if (value)
resultbox.innerHTML = value;
} catch (error) {
resultbox.innerHTML = "error occured";
console.log(error);
}
}
}
async function oneargfunc() {
if (contractInstance != null) {
try {
let conname = document.getElementById("conname");
let name = conname.value;
const value = await contractInstance.methods[this.id](name).call();
// const value = await contractInstance.methods.getAddr(name).call(); 이거랑 바로 윗줄이랑 같은내용인데 편하게 하려구 위에꺼 쓰는거래
resultbox.innerHTML = value;
} catch (error) {
resultbox.innerHTML = "error occured";
console.log(error);
}
}
}
async function showvalues() {
if (contractInstance != null) {
try {
const value = await contractInstance.methods[this.id]().call();
resultbox.innerHTML = value;
} catch (error) {
resultbox.innerHTML = "error occured";
console.log(error);
}
}
}
</script>
</head>
<body>
<h1> Name Registry Test </h1>
<br />
Contract Name: <input type="text" id="conname" value="">
Attribute: <input type="text" id="conattr" value="" size=100>
<br />
Result: <span id="resultbox"> </span>
<br />
<br />
<input type="button" id="changeOwner" value="changeOwner()" style="width:200px">
<br /> <br />
<input type="button" id="register" value="register()" style="width:200px">
<br /> <br />
<input type="button" id="setAddr" value="setAddr()" style="width:200px">
<br /> <br />
<input type="button" id="setDescription" value="setDescription()" style="width:200px">
<br /> <br />
<input type="button" id="unregister" value="unregister()" style="width:200px">
<br /> <br />
<input type="button" id="contracts" value="contracts" style="width:200px">
<br /> <br />
<input type="button" id="getAddr" value="getAddr" style="width:200px">
<br /> <br />
<input type="button" id="getDescription" value="getDescription" style="width:200px">
<br /> <br />
<input type="button" id="getOwner" value="getOwner" style="width:200px">
<br /> <br />
<input type="button" id="numContracts" value="numContracts" style="width:200px">
</body>
</html>