Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public class Block {
public long nonce;
private long timestamp;
public String transactionData;
public String previousBlockHash;
public Block(String transactionData) {
nonce = 0;
timestamp = System.currentTimeMillis();
this.transactionData = transactionData;
public String getHash() throws NoSuchAlgorithmException {
return CryptoHelper.sha256(transactionData + String.valueOf(timestamp)
+ String.valueOf(previousBlockHash)
+ String.valueOf(nonce));
public String toString() {
return String.format("%s\t%d\t%d\t%s", previousBlockHash, timestamp, nonce, transactionData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.