Code Monkey home page Code Monkey logo

Comments (5)

ac12644 avatar ac12644 commented on June 22, 2024

Hi! I got your point. So, when you add a new block this means you're creating a new coin. When you go to chain.js line 58, you'll see:

`const generateNextBlock = (txns) => {
const prevBlock = getLatestBlock(),
prevMerkleRoot = prevBlock.blockHeader.merkleRoot;
nextIndex = prevBlock.index + 1,
nextTime = moment().unix(),
nextMerkleRoot = CryptoJS.SHA256(1, prevMerkleRoot, nextTime).toString();

const blockHeader = new BlockHeader(1, prevMerkleRoot, nextMerkleRoot, nextTime);
const newBlock = new Block(blockHeader, nextIndex, txns);
blockchain.push(newBlock);
storeBlock(newBlock);
return newBlock;

};`

In this block, you are passing 4 parameters { 1, prevMerkleRoot, nextMerkleRoot, nextTime } you can also add more parameters like the name of sender and recipient. This information is stored in a hash which we consider a coin which you can modify based on your needs.

from blockchain.

mitmelon avatar mitmelon commented on June 22, 2024

Hi! I got your point. So, when you add a new block this means you're creating a new coin. When you go to chain.js line 58, you'll see:

`const generateNextBlock = (txns) => { const prevBlock = getLatestBlock(), prevMerkleRoot = prevBlock.blockHeader.merkleRoot; nextIndex = prevBlock.index + 1, nextTime = moment().unix(), nextMerkleRoot = CryptoJS.SHA256(1, prevMerkleRoot, nextTime).toString();

const blockHeader = new BlockHeader(1, prevMerkleRoot, nextMerkleRoot, nextTime);
const newBlock = new Block(blockHeader, nextIndex, txns);
blockchain.push(newBlock);
storeBlock(newBlock);
return newBlock;

};`

In this block, you are passing 4 parameters { 1, prevMerkleRoot, nextMerkleRoot, nextTime } you can also add more parameters like the name of sender and recipient. This information is stored in a hash which we consider a coin which you can modify based on your needs.

I get it now... But can I use this code on production server... To create a coin and allow miners to mine transactions...

I mean is this code secure to start my own coin creation like Bitcoin?

from blockchain.

ac12644 avatar ac12644 commented on June 22, 2024

Unfortunately not, this repo is for learning purposes. There are many things you can do to improve the code:

  • Confirmations: Each miner sends a message with a block. You can create a confirmation system to ensure the integrity of the data.

  • Transactions/data: You could implement transactions or data objects to address double-spending, transaction validation, and coinbase transactions.

  • levelDB: Once the P2P is initialized, you can create a script to retrieve and write all the blocks into the LevelDB database, validate them, and clean the database as needed.

from blockchain.

mitmelon avatar mitmelon commented on June 22, 2024

Unfortunately not, this repo is for learning purposes. There are many things you can do to improve the code:

  • Confirmations: Each miner sends a message with a block. You can create a confirmation system to ensure the integrity of the data.
  • Transactions/data: You could implement transactions or data objects to address double-spending, transaction validation, and coinbase transactions.
  • levelDB: Once the P2P is initialized, you can create a script to retrieve and write all the blocks into the LevelDB database, validate them, and clean the database as needed.

Okay thanks...

If I include all this, will the code be ready for productions...?

from blockchain.

ac12644 avatar ac12644 commented on June 22, 2024

yes

from blockchain.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.