-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathIOU.html
More file actions
96 lines (93 loc) · 2.26 KB
/
IOU.html
File metadata and controls
96 lines (93 loc) · 2.26 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="js/web3.min.js"></script>
</head>
<body>
<h2>借據平台</h2>
<input type="text" id="A" placeholder="請輸入借款人">
<input type="text" id="B" placeholder="請輸入貸款人">
<input type="text" id="money" placeholder="請輸入借款金額">
<input type="button" id="send" value="送出修改內容">
<script>
var web3 = new Web3(window.web3.currentProvider);
var Contract;
var abi = [
{
"constant": false,
"inputs": [
{
"name": "IOUMessage",
"type": "bytes32"
}
],
"name": "createIOU",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "data",
"type": "bytes32"
},
{
"indexed": false,
"name": "blockNumber",
"type": "uint256"
}
],
"name": "IOULog",
"type": "event"
},
{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"constant": true,
"inputs": [],
"name": "message",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
];
var address = '0xb1656f2DAE22D4AeD53F4766f75a06b9596F6e8e';
async function init(){
Contract = await new web3.eth.Contract(abi,address);
}
init();
async function send(){
var accounts = await web3.eth.getAccounts();
var A = document.getElementById('A').value;
var B = document.getElementById('B').value;
var money = document.getElementById('money').value;
var str = A+' borrowed '+money+' USD from '+B;
var hexStr = web3.utils.utf8ToHex(str)
Contract.methods.createIOU(hexStr)
.send({from:accounts[0]})
.then(function(data){
console.log(data);
})
}
document.getElementById('send').addEventListener('click',send);
</script>
</body>
</html>