-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSAPI_2.html
More file actions
85 lines (79 loc) · 2.25 KB
/
JSAPI_2.html
File metadata and controls
85 lines (79 loc) · 2.25 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JSAPI_1.html</title>
<a href="index.html">Back to Contents</a>
<script type="text/javascript">
var soliditySource = "contract metaCoin {\n"+
" mapping (address => uint) balances;\n" +
" function metaCoin() {\n" +
" balances[msg.sender] = 10000;\n" +
" }\n" +
" function send(address receiver, uint amount) {\n" +
" if (balances[msg.sender] < amount) return;\n" +
" balances[msg.sender] -= amount;\n" +
" balances[receiver] += amount;\n" +
" }\n" +
"}";
var contractDesc = [{
"name": "send(address,uint256)",
"type": "function",
"inputs": [
{
"name": "to",
"type": "address"
},
{
"name": "value",
"type": "uint256"
}
]
}];
function sendEther() {
web3.eth.transact({to: document.querySelector('#recipient').value ,value: document.querySelector('#value').value});
};
function createSolidityContract() {
var address = web3.eth.transact({code: web3.eth.solidity(soliditySource)});
contract = web3.eth.contract(address, contractDesc);
};
//function to send transaction using parameters from the HTML input boxes
function dataTransaction() {
var receiverAddress = document.querySelector('#receiverAddress').value;
var amount = document.querySelector('#amount').value;
contract.send(receiverAddress, amount);
};
</script>
</head>
<body>
<div>
<div>
<h3>Transact Example</h3>
</div>
<div>
<input id="recipient" type="text" placeholder="To">
<input id="value" type="text" placeholder="Value in Wei">
</div>
<div>
<button onclick="sendEther();">Send Ether</button>
</div>
<div>
<h3>Create a contract</h3>
</div>
<div>
<button onclick="createSolidityContract();">Create Solidity Coin Contract</button>
</div>
<div>
<h3>Send some coins</h3>
</div>
<div>
<input id="receiverAddress" class="form-control" type="text" placeholder="Receiver address"></input><br>
<input id="amount" class="form-control" type="text" placeholder="Amount"></input><br>
</div>
<button onclick="dataTransaction();">Send transaction</button>
</div>
<div>
Put in addresses prefixed with '0x' and hit 'Send transaction'
</div>
</body>
</html>