Repository navigation
Expand file tree
/
Copy path3.tutorial.slp.html
More file actions
122 lines (103 loc) · 4.49 KB
/
Copy path3.tutorial.slp.html
File metadata and controls
122 lines (103 loc) · 4.49 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<html>
<head>
<meta charset="utf-8">
<script src="https://rest-unstable.mainnet.cash/scripts/mainnet.js"></script>
<style>
div {
margin: 7pt;
}
</style>
</head>
<body>
<div style="display: flex; flex-direction: row;">
<div style="margin: 30px; flex: 50%;">
<h1>Bitcoin cash</h1>
<div>Wallet balance: <span id="balance"></span></div>
<div>Wallet balance USD: <span id="balanceUSD"></span></div>
<div>Deposit address: <span id="depositAddr"></span></div>
<div>Deposit QR: <img id="depositQr"/></div>
<div>
<input type="button" id="getSats" value="Get testnet satoshi"></input>
</div>
<div>
Send to address
<input id="sendAddr"></input>
<input type="button" id="send" value="Send"></input>
<input type="button" id="sendMax" value="Send All Funds"></input>
</div>
</div>
<!-- slp -->
<div style="margin: 30px; flex: 50%;">
<h1>Simple ledger tokens</h1>
<div>Wallet balance: <span id="slpBalance"></span></div>
<div>Wallet balance USD: <span id="slpBalanceUSD"></span></div>
<div>Deposit address: <span id="slpDepositAddr"></span></div>
<div>Deposit QR: <img id="slpDepositQr"/></div>
<div>
<button type="button" id="getSlp">Get testnet slp tokens</button>
</div>
<div>
Send to slp address
<input id="slpSendAddr"></input>
<input type="button" id="slpSend" value="Send SLP"></input>
<input type="button" id="slpSendMax" value="Send All SLP Tokens"></input>
</div>
</div>
</div>
</body>
<script>
async function run() {
const wallet = await TestNetWallet.newRandom();
const balance = await wallet.getBalance();
document.querySelector('#balance').innerText = `${balance.sat} testnet satoshi`;
document.querySelector('#balanceUSD').innerText = `$${balance.usd}`;
const addr = await wallet.getDepositAddress();
document.querySelector('#depositAddr').innerText = addr;
const qr = await wallet.getDepositQr();
document.querySelector('#depositQr').src = qr.src;
wallet.watchBalance((balance) => {
document.querySelector('#balance').innerText = `${balance.sat} testnet satoshi`;
document.querySelector('#balanceUSD').innerText = `$${balance.usd}`;
});
document.querySelector('#getSats').addEventListener("click", async () => {
await wallet.getTestnetSatoshis();
});
document.querySelector('#send').addEventListener("click", async () => {
const addr = document.querySelector('#sendAddr').value;
await wallet.send([{cashaddr: addr, value: 1000, unit: "sat"}]);
alert('Sent 1000 sats to ' + addr);
});
document.querySelector('#sendMax').addEventListener("click", async () => {
const addr = document.querySelector('#sendAddr').value;
await wallet.sendMax(addr);
alert('Sent all funds to ' + addr);
});
const tokenId = "132731d90ac4c88a79d55eae2ad92709b415de886329e958cf35fdd81ba34c15";
const slpBalance = await wallet.slp.getBalance(tokenId);
document.querySelector('#slpBalance').innerText = `${slpBalance.value} ${slpBalance.ticker}`;
document.querySelector('#slpBalanceUSD').innerText = `???`;
const slpAddr = await wallet.slp.getDepositAddress();
document.querySelector('#slpDepositAddr').innerText = slpAddr;
const slpQr = await wallet.slp.getDepositQr();
document.querySelector('#slpDepositQr').src = slpQr.src;
wallet.slp.watchBalance((slpBalance) => {
document.querySelector('#slpBalance').innerText = `${slpBalance.value} ${slpBalance.ticker}`;
document.querySelector('#slpBalanceUSD').innerText = `???`;
}, tokenId);
document.querySelector('#getSlp').addEventListener("click", async () => {
await wallet.getTestnetSlp(tokenId);
});
document.querySelector('#slpSend').addEventListener("click", async () => {
const addr = document.querySelector('#slpSendAddr').value;
await wallet.slp.send([{slpaddr: addr, value: 1, tokenId: tokenId}]);
alert('Sent 1 slp to ' + addr);
});
document.querySelector('#slpSendMax').addEventListener("click", async () => {
const addr = document.querySelector('#slpSendAddr').value;
await wallet.slp.sendMax(addr);
alert('Sent all slp funds to ' + addr);
});
}
run();
</script>
</html>