Hi Miguel,
Many thanks for taking the time to answer my question, I will look to see if I can do as you say, I was just not sure if using a class function if it would be as simple as the last line of the code that I have updated below:
class Block {
constructor(index, timestamp, transactions, reference, data, precedingHash = " ") {
this.index = index;
this.timestamp = Date.now();
this.reference = uuidv4();
this.transactions = Transaction;
this.data = data;
this.precedingHash = precedingHash;
this.hash = this.computeHash();
this.nonce = 0;
}
computeHash() {
return SHA256(
this.index +
this.precedingHash +
this.timestamp +
this.reference +
JSON.stringify(this.data) +
JSON.stringify(this.transactions) +
this.nonce
).toString();
}
mineBlock(difficulty) {
while (
this.hash.substring(0, difficulty) !== Array(difficulty + 1).join("0")
) {
this.nonce++;
this.hash = this.computeHash();
}
console.log("BLOCK MINED:" + this.hash);
}
}
module.exports = Block;
or alternatively
export default Block;
I will follow your suggestion and also attempt the above examples to see if I can achieve creating them as JSW and will update with findings.
Many thanks again,
Si