I looking for long term cooperation possible client.

Stiven_1 0 Tallied Votes 9 Views Share

I am a full-stack full-time developer.
I have 5 years of development experience and My basic skills are Blockchain, TypeScript, ReactJS, Shopify.
I am a full-time dev, so I can answer your inquiries at any time.
I can work on weekends if needed and communicate fluently in English.

const crypto = require("crypto");

class Block {
  constructor(index, timestamp, data, previousHash = "") {
    this.index = index;
    this.timestamp = timestamp;
    this.data = data;
    this.previousHash = previousHash;
    this.hash = this.calculateHash();
  }

  calculateHash() {
    return crypto
      .createHash("sha256")
      .update(this.index + this.timestamp + JSON.stringify(this.data) + this.previousHash)
      .digest("hex");
  }
}

class Blockchain {
  constructor() {
    this.chain = [this.createGenesisBlock()];
  }

  createGenesisBlock() {
    return new Block(0, new Date().toISOString(), "Genesis Block", "0");
  }

  getLatestBlock() {
    return this.chain[this.chain.length - 1];
  }

  addBlock(newBlock) {
    newBlock.previousHash = this.getLatestBlock().hash;
    newBlock.hash = newBlock.calculateHash();
    this.chain.push(newBlock);
  }

  isValid() {
    for (let i = 1; i < this.chain.length; i++) {
      const curr = this.chain[i];
      const prev = this.chain[i - 1];

      if (curr.hash !== curr.calculateHash()) return false;
      if (curr.previousHash !== prev.hash) return false;
    }
    return true;
  }
}

// Usage
let myBlockchain = new Blockchain();
myBlockchain.addBlock(new Block(1, new Date().toISOString(), { amount: 100 }));
myBlockchain.addBlock(new Block(2, new Date().toISOString(), { amount: 50 }));

console.log(JSON.stringify(myBlockchain, null, 2));
console.log("Is blockchain valid?", myBlockchain.isValid());
Dani 4,645 The Queen of DaniWeb Administrator Featured Poster Premium Member

You might want to check out Upwork or Toptal to get freelance development work.

May I ask what the code you provided here does? It seems to just be a constructor function with some getters and setters, but is missing the rest of it. Was it written by ChatGPT?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.