-
Notifications
You must be signed in to change notification settings - Fork 97
/
index.html
109 lines (97 loc) · 2.76 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
<html>
<head>
<link rel='shortcut icon' type='image/x-icon' href='/favicon.ico' />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
crossorigin="anonymous">
<title>Ethersjs Demo</title>
<style>
body {
background-color: black;
text-align: center;
color: white;
font-family: Arial, Helvetica, sans-serif;
}
</style>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
</head>
<body>
<script charset="utf-8" src="https://cdn.ethers.io/scripts/ethers-v4.min.js" type="text/javascript">
</script>
<div class="container">
<div class="form-group">
<h1>This is my Ethersjs Demo!</h1>
<p> Here we can set or get the mood: </p>
<div class="row">
<div class="col offset-md-4 col-md-4">
<label for="mood">Input Mood:</label>
<input type="text" class="form-control" id="mood">
</div>
</div>
<div class="row mt-2">
<div class="col offset-md-4 col-md-2">
<button class="btn btn-primary btn-block" onclick="getMood()"> get Mood </button>
</div>
<div class="col col-md-2">
<button class="btn btn-light btn-block" onclick="setMood()"> set Mood</button>
</div>
</div>
</div>
</div>
<script>
window.ethereum.enable()
var provider = new ethers.providers.Web3Provider(web3.currentProvider, 'ropsten');
var MoodContractAddress = "0xF09d9bAc28E94A03BD66D943Cfc950484A8B9759";
let MoodContractABI = [
{
"constant": true,
"inputs": [],
"name": "getMood",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "string",
"name": "_mood",
"type": "string"
}
],
"name": "setMood",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]
provider.listAccounts().then(function (accounts) {
signer = provider.getSigner(accounts[0]);
MoodContract = new ethers.Contract(MoodContractAddress, MoodContractABI, signer);
})
async function getMood() {
getMoodPromise = MoodContract.getMood();
var Mood = await getMoodPromise;
alert("The current mood is: " + Mood);
}
async function setMood() {
mood = $("#mood").val()
if (mood == "") {
alert("Please input mood");
} else {
setMoodPromise = MoodContract.setMood(mood);
await setMoodPromise;
}
}
</script>
</body>
</html>