A simple JavaScript package for creating and managing a basic blockchain.
You can install this package via npm:
npm install web3utility
const Blockchain = require('web3utility');
// Create a new instance of the blockchain
const blockchain = new Blockchain();
// Create a new transaction
const transactionId = blockchain.createNewTransaction('sender_address', 'recipient_address', 100);
// Create a new block
const previousBlock = blockchain.getLastBlock();
const previousBlockHash = previousBlock.hash;
const nonce = 100; // For demonstration, in real-world scenarios, this would be calculated
const newBlock = blockchain.createNewBlock(nonce, previousBlockHash);
console.log('Blockchain:', blockchain.chain);
Creates a new instance of the Blockchain class.
Creates a new block in the blockchain.
-
nonce
(number): The nonce for the new block. -
previousBlockHash
(string): The hash of the previous block.
Returns the last block in the blockchain.
Creates a new transaction.
-
sender
(string): The address of the sender. -
recipient
(string): The address of the recipient. -
amount
(number): The amount to be transferred.
This project is licensed under the MIT License - see the LICENSE file for details.