This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
2
How do scale up in javascript? The code does what I want it to do on one transaction, but how about 20+?
Post Body
Sorry for the stupid questions. But, I have some code that checks a single transaction of a particular crypto address. Then, the code appends the transaction ID to a couple of API's, and returns some strings, and a reply box. (The code will be below)
My question is, how do I scale this code to perform the same process on the latest 10 transactions instead of just one? I am not able to use a javascript framework for this project. Thank you. Here is the code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Fetching Text from URL</title>
<script type="text/javascript" src="https://unpkg.com/[email protected]/bsv.min.js"></script>
</head>
<body>
<h2>Comment/Post by:</h2>
<p id="last-address"></p>
<h2>Text:</h2>
<pre id="text-container"></pre>
<h2>Reply To Post</h2>
<p id="transaction-id"></p>
<input type="text" id="txt" style="width: 300px; height: 50px;" onkeyup="render()">
<div id="mb"></div>
<script src="https://www.moneybutton.com/moneybutton.js"></script>
<script>
let lastAddress;
fetch('https://api.whatsonchain.com/v1/bsv/main/address/1JxhdrQJ2rB9E79kRHBpzrm97czw4NFAct/history')
.then(response => response.json())
.then(data => {
const firstTxId = data[0].tx_hash;
const url = `https://api.whatsonchain.com/v1/bsv/main/tx/hash/${firstTxId}`;
return fetch(url);
})
.then(response => response.json())
.then(data => {
const lastOutput = data.vout[data.vout.length - 1];
lastAddress = lastOutput.scriptPubKey.addresses[lastOutput.scriptPubKey.addresses.length - 1];
const url = `https://bico.media/${data.txid}`;
return fetch(url)
.then(response => response.text())
.then(text => ({ lastAddress, text, txid: data.txid }));
})
.then(({ lastAddress, text, txid }) => {
const lastAddressElement = document.getElementById('last-address');
const textContainer = document.getElementById('text-container');
const transactionIdElement = document.getElementById('transaction-id');
lastAddressElement.innerHTML = lastAddress;
textContainer.innerHTML = text;
transactionIdElement.innerHTML = txid;
})
.catch(error => console.error(error));
const render = () => {
const div = document.getElementById('mb');
const text = document.getElementById('txt').value;
const script = bsv.Script.buildSafeDataOut(['19HxigV4QyBv3tHpQVcUEQyq1pzZVdoAut', text, 'text/plain']).toASM();
moneyButton.render(div, {
outputs: [{
script: script,
amount: '0.00001',
currency: 'USD'
},
{
address: "1JxhdrQJ2rB9E79kRHBpzrm97czw4NFAct",
amount: "0.002",
currency: "USD"
},
{
address: lastAddress,
amount: "0.002",
currency: "USD"
}
]
});
};
</script>
</body>
</html>
Author
User Suspended
Account Strength
0%
Suspended 4 months ago
Account Age
1 year
Verified Email
Yes
Verified Flair
No
Total Karma
8
Link Karma
5,901
Comment Karma
1,059
Profile updated: 1 week ago
Posts updated: 1 year ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnjavasc...