-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
181 lines (173 loc) · 5.42 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html lang="en">
<head>
<title>Toll Collection</title>
<script
type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.2.7-rc.0/web3.min.js"
></script>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
<script src="https://www.gstatic.com/firebasejs/8.6.5/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.5/firebase-database.js"></script>
<style>
body {
box-sizing: border-box;
margin: 0px;
padding: 0px;
background-color: rgb(234, 234, 234);
text-align: center;
}
button,
p {
font-family: "Times New Roman", Times, serif;
}
.btn {
font-size: 18px;
}
p {
font-size: 23px;
}
button:hover {
background-color: rgb(0, 174, 255);
}
input {
width: 150px;
height: 40px;
font-size: medium;
text-align: center;
}
.navbar-brand {
padding-left: 40%;
font-size: 35px;
font-family: "Brush Script MT", cursive;
}
.row {
padding-left: 8%;
}
.card {
margin: 40px 15px 30px 20px;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="/">Toll Transaction</a>
<button
class="navbar-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
</div>
</nav>
<br /><br />
<div class="row">
<div class="col-md-5">
<div class="card">
<div class="card-body">
<p id="accountArea">MetaMask account is not connected</p>
<button onclick="connectMetamask()" class="btn btn-warning btn-lg">
CONNECT TO METAMASK
</button>
</div>
</div>
</div>
<div class="col-sm-5">
<div class="card">
<div class="card-body">
<p id="contractArea">Smart Contract address is not verified</p>
<button onclick="connectContract()" class="btn btn-primary btn-lg">
CONNECT TO SMART CONTRACT
</button>
</div>
</div>
</div>
<div class="col-sm-5">
<div class="card last">
<div class="card-body">
<p id="dataArea">Smart Contract is not connected</p>
<button onclick="readContract()" class="btn btn-success btn-lg">
GET DATA FROM CONTRACT
</button>
</div>
</div>
</div>
<div class="col-sm-5">
<div class="card">
<div class="card-body">
<p>The total collected amount is</p>
<input type="text" id="inputArea" /> <br /><br />
<button
type="button"
class="btn btn-danger btn-lg"
aria-current="true"
onclick="writeContract()"
>
Send to the Contract
</button>
<p id="writtenData"></p>
</div>
</div>
</div>
</div>
<script
src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"
integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p"
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js"
integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF"
crossorigin="anonymous"
></script>
<script>
var res = "https://travelling-app-48ca9-default-rtdb.firebaseio.com/";
// Connect Metamask
let acc;
const connectMetamask = async () => {
if (window.ethereum !== "undefined") {
const accs = await ethereum.request({
method: "eth_requestAccounts",
});
acc = accs[0];
document.getElementById(
"accountArea"
).innerHTML = `MetaMask account Address is ${acc}`;
}
};
// Connect to smart contract
const connectContract = async () => {
const ABI = ["Enter your ABI here"];
const Address = "Enter deployed smart contract address here";
window.web3 = await new Web3(window.ethereum);
window.contract = await new window.web3.eth.Contract(ABI, Address);
document.getElementById(
"contractArea"
).innerHTML = `Connection successful and address: ${Address}`;
};
// Read the data from contract
const readContract = async () => {
const data = await window.contract.methods.getAmount().call();
document.getElementById("dataArea").innerHTML = data;
};
// Write the data to contract
const writeContract = async () => {
const EnteredAmnt = document.getElementById("inputArea").value;
await window.contract.methods
.CheckAmount(EnteredAmnt)
.send({ from: acc });
};
</script>
</body>
</html>