A simple Blockchain project that stores randomly generated user transactions into blocks. It only uses the built-in python modules.
- Download Python 3
- Download/Clone the repo
- Open CMD/Terminal in the project directory and run
python block.py
to generate the blockchain - The Blockchain will save to
simplyblock.json
Generating a new blockchain:
simplyBlockContent={'blockIndex':0,'lasthash': None,'useract':[userAccount],"txn":[None]}
simplyBlock={'hash':getHash(simplyBlockContent),'block':simplyBlockContent}
simplyChain=[simplyBlock]
Opening existing blockchain:
with codecs.open('simplyblock.json', 'r') as outfile:
simplyChain=json.load(outfile)
Create transaction to process(John sends Ron 57 units):
transactionToProcess = [{'reciever':'Ron','sender':'John','amount':57}]
Generate random transactions to process:
transactionToProcess = generateTransactions(userAccount,15)
Process transactions to new block:
simplyChain.append(processTransactionsToBlock(userAccount,simplyChain,transactionToProcess))
userAccount=getUpdatedUserAccount()
Print last block:
print(simplyChain[-1])
Print entire chain:
print(simplyChain)
Verify Transaction(returns True if Valid, False if Invalid)
verifyTransaction(transaction, userAccount)
Running blockServer
python blockServer.py