-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo2.html
74 lines (62 loc) · 1.54 KB
/
demo2.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
<html>
<head><title> Demo Page </title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.js"></script>
<script>
var account;
window.addEventListener('load', async () => {
console.log("In Event Listener");
if (typeof window.ethereum !== 'undefined') {
console.log("MetaMask is Available :) !");
}
// Modern DApp browsers
if (window.ethereum) {
window.web3 = new Web3(ethereum);
// To Capture the account details from MetaMask
const accounts = await ethereum.enable();
account = accounts[0];
}
console.log(account);
abi = [
{
"inputs": [
{
"internalType": "uint256",
"name": "num",
"type": "uint256"
}
],
"name": "store",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "retrieve",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
];
contractaddress = '0x4F92ff0B8A897Ce5deeeC6B12B4d7E219B4225E7';
var myContract = new web3.eth.Contract(abi,contractaddress, {from: account, gasPrice: '4000000000', gas: '8000000'});
var result = myContract.methods.store(20).send(function (err, result) {
console.log("Result: ", result);
if (result) { console.log(result); }
});
var result = myContract.methods.retrieve().call(function (err, result) {
console.log("Result: ", result);
if (result) { console.log(result[0]); }
});
});
</script>
</body>
</html>