2.0.1 • Published 3 years ago

izigma-blockchain v2.0.1

Weekly downloads
41
License
MIT
Repository
github
Last release
3 years ago

iZigma Blockchain

This is a blockchain library that can be used to create a complete blockchain network with multiple blockchain support. To launch a you only need to create a object in your project using the library. If you want more blockchains, create more objects. To mine blocks, read the chain or to create trasacations use the methods binded to the object. Complete method list can be obtain by reading the index.js file of the library.

Configuration

To use or test this library you need to add a configuration file. Create a file named izigma-config.js on the project root directory.

Then past the following code

const DIFFICULTY = 2;
const MINE_RATE = 1000;
const INITIAL_BALANCE = 500;
const MINING_REWARD = 50;
module.exports = { DIFFICULTY,MINE_RATE,INITIAL_BALANCE,MINING_REWARD};

Here the DIFFICULTY attribute is the initial difficulty for the proof of work consesus. MINE_RATE is the how often a block is created in the mine in mille seconds. INITIAL_BALANCE hold the wallate balance of the node. And MINING_REWARD is the reward recives for the miner for doing mining works...

Method List

  • addBlock(data) -> add a new block to the chain without mining.
  • getChain() -> Read the blockchain.
  • isValidChain(chain) -> Check incoming chain from the network is valid compaird to the current blockchain
  • replaceChain(newChain) -> Replace the current chain with a new chain
  • getChainFileName() -> geth the blockchain file name
  • calculateBlockchainHash() -> calculate a hash value for the whole chain
  • createWallet(publicKey, privateKey, algorithm) -> use only when you need to change the wallet.if not auto generated wallet is there,keys generated with RSA algorithm
  • createTransaction(recipient, amount) -> create a new transaction
  • createRecord(data) -> create a new record
  • calculateBalance() -> calculate the wallet balance for the chain
  • calculateSpecialCoinBalance(coin) -> calculate the balance for a customly generated coin
  • getPublicKey() -> Get the public key of the node
  • isContributed() -> Check is there any previous transactions
  • getTransactionPool() -> get the transactions in the transaction pool
  • clearTransactionPool() -> clear transaction pool
  • updateOrAddTransactionToTransactionPool(transaction) -> add or update existing transaction in the pool
  • getSpecialCoinTransactionPool() -> get the custom coin transactions in the transaction pool
  • clearSpecialCoinTransactionPool() -> clear special coin transactions in the pool
  • updateOrAddTransactionToSpecialCoinTransactionPool(transaction) -> add or update existing custom coin transaction in the pool
  • getRecordPool() -> get the current record pool
  • clearRecordPool() -> clear the current record pool
  • addRecordToRecordPool() -> add record to the the record pool
  • mineTransactions() -> mine the transaction
  • mineRecords() -> mine the records
  • generateSpecailCoinandDeploy(recivers, coinsForEachReciver, coinName) -> create and deploy a custome coin to the blockchain

Samaple Code

const express = require ('express');
const bodyParser = require('body-parser');
const Blockchain = require('izigma-blockchain');

const HTTP_PORT = process.env.HTTP_PORT || 3001;

const app = express();
//To work with more chains create more objects like chain_2,chain_3
const chain = new Blockchain();
chain.createWallet();
app.use(bodyParser.json());

app.get('/blocks',async(req,res) =>{
    let blockchain = await chain.getChain();
    res.json(blockchain);
});

app.post('/mine',async(req,res) =>{
    const block = await chain.addBlock(req.body.data);
    console.log(`New block added : ${ block.toString()}`);

    let blockchain = await chain.getChain();

    res.redirect('/blocks');
});

app.get('/transactions',(req,res)=>{
    res.json(chain.getTransactionPool());
})

app.post('/transact',(req,res)=>{
    const {recipient, amount} = req.body;
    const transaction = chain.createTransaction(recipient,amount);
    res.redirect('/transactions');
});

app.get('/mine-transactions',(req,res)=>{
    const block = chain.mineTransaction();
    chain.clearTransactionPool();
    console.log(`New block added : ${block.toString()}`);
    res.redirect('/blocks');
});

app.get('/public-key',(req,res)=>{
    res.json({
        publicKey: chain.getPublicKey()
    });
})

app.listen(HTTP_PORT, async () => {
  console.log(`Listeing on port ${HTTP_PORT}`);
});
2.0.1

3 years ago

2.0.0

3 years ago

1.9.4

4 years ago

1.9.3

4 years ago

1.9.2

4 years ago

1.9.1

4 years ago

1.9.0

4 years ago

1.8.2-SNAPSHOT

4 years ago

1.8.1-SNAPSHOT

4 years ago

1.8.0-SNAPSHOT

4 years ago

1.7.4

4 years ago

1.7.3

4 years ago

1.7.2

4 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.6.6

4 years ago

1.6.5

4 years ago

1.6.4

4 years ago

1.6.3

4 years ago

1.6.2

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.7

4 years ago

1.3.8

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.0.0

4 years ago