-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo6.html
97 lines (88 loc) · 1.98 KB
/
demo6.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
<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": "pharmastore_id",
"type": "uint256"
},
{
"internalType": "string",
"name": "_pharmastore_name",
"type": "string"
},
{
"internalType": "string",
"name": "_pharmastore_address",
"type": "string"
}
],
"name": "store",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "pharmastore_id",
"type": "uint256"
}
],
"name": "retreive",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
},
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
}
];
contractaddress = '0xE2f1310B914C1e6C54a58Ad307C19715F5daB695';
var myContract = new web3.eth.Contract(abi,contractaddress, {from: account, gasPrice: '4000000000', gas: '8000000'});
var result = myContract.methods.store().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>