j"19HxigV4QyBv3tHpQVcUEQyq1pzZVdoAutM?<html>
<head>
<script src="b://3412b9beb4234acea4d3406c38af5e283cc91486abeddfa80fcb45842c1f99c2"></script>
<script>
let privateKey;
let address;
let qrcode;
let utxos = [];
let chunkSize = 90000;
function initialize() {
let wif = localStorage.getItem('privateKey');
if (wif) {
privateKey = bsv.PrivateKey.fromWIF(wif);
}
if (!privateKey) {
privateKey = bsv.PrivateKey.fromRandom();
localStorage.setItem('privateKey', privateKey.toWIF());
}
address = privateKey.toAddress();
document.getElementById('address').innerText = address;
fetch('https://api.bitindex.network/api/v2/addrs/utxos?address=' + address, {
headers: {
api_key: '22qtEpsphEv2ZtP8JkBiKD65bLQ26PxyJ66obK42uCGeb3b8MetH1bK5n4xEF3yxQ4'
}
}).then((res) => res.json())
.then(({ data }) => {
utxos = data;
balance = data.reduce((balance, utxo) => {
return balance + utxo.satoshis;
}, 0);
document.getElementById('confirmed').innerText = utxos.filter((utxo) => utxo.height).length;
document.getElementById('unconfirmed').innerText = utxos.filter((utxo) => !utxo.height).length;
document.getElementById('balance').innerText = balance / 100000000;
})
}
function split() {
let transaction = new bsv.Transaction()
.from(utxos);
for (let i = 0; i < 25; i++) {
transaction.to(address, 120000);
}
transaction.change(address);
transaction.sign(privateKey);
fetch('https://api.bitindex.network/api/tx/send', {
method: 'POST',
body: JSON.stringify({ rawtx: transaction.toString() }),
headers: {
api_key: '22qtEpsphEv2ZtP8JkBiKD65bLQ26PxyJ66obK42uCGeb3b8MetH1bK5n4xEF3yxQ4',
'Content-Type': 'application/json'
}
}).then((res) => console.log(res.json()))
}
function upload() {
const file = document.getElementById('file').files[0];
const reader = new FileReader();
const txns = [];
reader.onload = (e) => {
let buffer = reader.result;
console.log(buffer);
const chunks = buffer.byteLength / chunkSize;
console.log(`${chunks} chunks`);
let i;
for (i = 0; i < chunks; i++) {
let txn = new bsv.Transaction()
.from(utxos[i])
.addData([
'1ChDHzdd1H4wSjgGMHyndZm6qxEDGjqpJL',
bsv.deps.Buffer.from(buffer.slice(i * chunkSize, (i + 1) * chunkSize))
])
.change(address)
.sign(privateKey);
txns.push(txn);
}
let bcatTxn = new bsv.Transaction()
.from(utxos[i])
.addData([
'15DHFxWZJT58f9nhyGnsRBqrgwK4W6h4Up',
'bottle upload',
file.type,
'',
file.name,
'',
...txns.map((txn) => bsv.deps.Buffer.from(txn.hash, 'hex'))
])
.change(address)
.sign(privateKey);
txns.push(bcatTxn);
txns.reduce((acc, txn) => {
return acc.then(() => {
return fetch('https://api.bitindex.network/api/v2/tx/send', {
method: 'POST',
body: JSON.stringify({ hex: txn.toString() }),
headers: {
api_key: '22qtEpsphEv2ZtP8JkBiKD65bLQ26PxyJ66obK42uCGeb3b8MetH1bK5n4xEF3yxQ4',
'Content-Type': 'application/json'
}
})
.then((res) => {
if(!res.ok) {
return Promise.reject(res.json())
}
});
})
}, Promise.resolve())
.catch(console.error)
.then(() => document.getElementById('txid').innerText = bcatTxn.hash);
console.log(bcatTxn.hash);
}
reader.readAsArrayBuffer(file);
}
function refund() {
let refundAddress = bsv.Address.fromString(document.getElementById('refundAddress').value);
let total = utxos.reduce((acc, utxo) => {
return acc + utxo.satoshis;
}, 0);
let txn = new bsv.Transaction()
.from(utxos)
.to(refundAddress, total - 5000)
.sign(privateKey);
return fetch('https://api.bitindex.network/api/v2/tx/send', {
method: 'POST',
body: JSON.stringify({ hex: txn.toString() }),
headers: {
api_key: '22qtEpsphEv2ZtP8JkBiKD65bLQ26PxyJ66obK42uCGeb3b8MetH1bK5n4xEF3yxQ4',
'Content-Type': 'application/json'
}
})
.then((res) => res.json())
.then(console.log);
}
</script>
</head>
<body onload="initialize()">
<p>
Address: <span id="address"></span>
</p>
<p>
Balance: <span id="balance"></span>
</p>
<h4>UTXOs</h4>
<p>
Confirmed: <span id="confirmed">?</span><br>
Unconfirmed: <span id="unconfirmed">?</span>
</p>
<button onclick="split()">Split 25 Times</button>
<h4>Upload</h4>
<p>
<input type="file" id="file">
</p>
<button onclick="upload()">Upload</button>
<p>
<span id="txid">?</span>
</p>
<h4>Refund</h4>
<p>
<input type="text" id="refundAddress">
</p>
<button onclick="refund()">Refund</button>
</body>
</html> text/html
https://whatsonchain.com/tx/f6015d25e4eaa3a21934fb63395c924e70ddd40ec24e144bd27a7ca4612614c0