-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_blockapps.html
More file actions
86 lines (71 loc) · 3.3 KB
/
example_blockapps.html
File metadata and controls
86 lines (71 loc) · 3.3 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
<html>
<body>
<script src="ethlightjs.min.js"></script>
<script>
var helpers = ethlightjs.helpers
var web3api = new ethlightjs.blockchainapi.web3api("http://104.236.65.136:8545")
var api = new ethlightjs.blockchainapi.blockappsapi()
var web3 = web3api.getWeb3()
var password = 'mypassword'
var keystore = undefined
var addresses = undefined
function checkNonce(){
var addr = document.getElementById('sendFrom').value
console.log("addr is " + addr)
var nonce = api.getNonce(addr, function(nonce){
document.getElementById('nonce').value = nonce
console.log("nonce is: " + nonce)
})
}
function setSeed() {
var seed = document.getElementById('seed').value
keystore = new ethlightjs.keystore(seed, password)
var addr0 = keystore.generateNewAddress(password)
var bal0 = api.getBalance(addr0, function(bal){
document.getElementById('addr0').innerHTML = addr0 + ' (' + (bal / 1.0e18) + ' ETH)'
})
var addr1 = keystore.generateNewAddress(password)
var bal1 = api.getBalance(addr1, function(bal){
document.getElementById('addr1').innerHTML = addr1 + ' (' + (bal / 1.0e18) + ' ETH)'
})
var addr2 = keystore.generateNewAddress(password)
var bal2 = api.getBalance(addr2, function(bal){
document.getElementById('addr2').innerHTML = addr2 + ' (' + (bal / 1.0e18) + ' ETH)'
})
addresses = keystore.getAddresses()
}
function randomSeed() {
var randomSeed = ethlightjs.keystore.generateRandomSeed()
document.getElementById('seed').value = randomSeed
}
function sendEth() {
var fromAddr = document.getElementById('sendFrom').value
var toAddr = document.getElementById('sendTo').value
var valueEth = document.getElementById('sendValueAmount').value
var value = parseFloat(valueEth)*1.0e18// what is the right conversion here?
console.log('**' + fromAddr + '**')
var accNonce = parseInt(document.getElementById('nonce').value)
console.log(accNonce)
txObj = {gasLimit: 30000, nonce: accNonce}
helpers.sendValueTx (fromAddr, toAddr, value, txObj, api, keystore, password)
}
</script>
<h1>LightWallet</h1>
<h2>Seed</h2>
<div><input type="text" id="seed" value="unhappy nerve cancel reject october fix vital pulse cash behind curious bicycle"></input><button onclick="setSeed()">Set Seed</button><button onclick="randomSeed()">Random Seed</button></div>
<div>
<h2>Addresses</h2>
<div id="addr0"></div>
<div id="addr1"></div>
<div id="addr2"></div>
<div id="signedTx"></div>
<div id="balance"></div>
<h2>Send Ether</h2>
<div>From: <input type="text" id="sendFrom" value="dedb49385ad5b94a16f236a6890cf9e0b1e30392"></input></div>
<div><button onclick="checkNonce()">Check nonce</button></div>
<div>To: <input type="text" id="sendTo" value="88ada7b45ac3ef7ba179378fa830c639e514d067"></input></div>
<div>Ether: <input type="text" id="sendValueAmount" value="1"></div>
<div>Nonce: <input type="number" id="nonce" value=0></div>
<div><button onclick="sendEth()">Send Ether</button></div>
</body>
</html>