forked from trezor/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
composetx-push.html
69 lines (60 loc) · 2.48 KB
/
composetx-push.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
<!DOCTYPE html>
<html>
<head>
<title>TREZOR Compose & Sign Transaction Test</title>
<script>
function trezorComposeTx() {
var coin = document.getElementById('coin').value;
var address = document.getElementById('address').value;
var amount = document.getElementById('amount').value;
var outputs = [{
address: address,
amount: parseInt(amount)
}];
TrezorConnect.setCurrency(coin);
// TrezorConnect.setCurrencyUnits('btc'); // default value is mBTC (used only for Bitcoin)
TrezorConnect.closeAfterSuccess(false);
TrezorConnect.closeAfterFailure(false);
TrezorConnect.composeAndSignTx(outputs, function (response) {
TrezorConnect.closeAfterSuccess(true);
if (response.success) {
TrezorConnect.pushTransaction(response.serialized_tx, function (pushResult) {
if (pushResult.success) {
console.log('Transaction pushed. Id:', pushResult.txid); // ID of the transaction
} else {
console.error('Error:', pushResult.error); // error message
}
document.getElementById("response").innerHTML = document.getElementById("response").innerHTML + JSON.stringify(pushResult, undefined, 2);
});
} else {
console.error('Error:', response.error); // error message
}
document.getElementById("response").innerHTML = document.getElementById("response").innerHTML + JSON.stringify(response, undefined, 2);
});
}
</script>
</head>
<body>
Coin:
<select id="coin">
<option selected>Bitcoin</option>
<option>Bitcoin Cash</option>
<option>Litecoin</option>
<option>Dash</option>
<option>Zcash</option>
<option>Testnet</option>
</select>
Address: <input type="text" id="address" size="40"
value="17RdK7aSerDgahHu858MMRG82ePTQxytc4">
Satoshis: <input type="number" id="amount" value="20000">
<button onclick="trezorComposeTx()">Compose & Sign & Push</button>
<pre id="response"></pre>
<script>
if (window.location.hostname === 'localhost') {
window.TREZOR_POPUP_ORIGIN = window.location.origin;
window.TREZOR_POPUP_URL = window.TREZOR_POPUP_ORIGIN + '/popup/popup.html';
}
</script>
<script src="../connect.js"></script>
</body>
</html>