Coder Social home page Coder Social logo

blockchain-python-tutorial's Introduction

Blockchain Python tutorial

Important: This project is for educational purposes only and the source code shouldn't be use in production as it doesn't have good security, doesn't scale well and lacks many important features.

The github repository contains a basic implementation of a blockchain and its client using Python. This blockchain has the following features:

  • Possibility of adding multiple nodes to the blockchain
  • Proof of Work (PoW)
  • Simple conflict resolution between nodes
  • Transactions with RSA encryption

The blockchain client has the following features:

  • Wallets generation using Public/Private key encryption (based on RSA algorithm)
  • Generation of transactions with RSA encryption

This github repository also contains 2 dashboards:

  • "Blockchain Frontend" for miners
  • "Blockchain Client" for users to generate wallets and send coins

Dependencies

How to run the code

  1. To start a blockchain node, go to blockchain folder and execute the command below: python blockchain.py -p 5000
  2. You can add a new node to blockchain by executing the same command and specifying a port that is not already used. For example, python blockchain.py -p 5001
  3. TO start the blockchain client, go to blockchain_client folder and execute the command below: python blockchain_client.py -p 8080
  4. You can access the blockchain frontend and blockchain client dashboards from your browser by going to localhost:5000 and localhost:8080

Visit my Blog : http://adilmoujahid.com

blockchain-python-tutorial's People

Contributors

adilmoujahid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blockchain-python-tutorial's Issues

No module named parse

Situation: I want to start a blockchain node

Action: sudo python blockchain.py -p 5000

Result:

Traceback (most recent call last):
  File "blockchain.py", line 33, in <module>
    from urllib.parse import urlparse
ImportError: No module named parse

Attemption:
pip install parse(install success, does not solve problem)
pip install urllib(No matching distribution found for urllib)
pip install urlparse(No matching distribution found for urlparse)

Solution:
In blockchain.py, change
from urllib.parse import urlparse
to
from urlparse import urlparse

Could you please tell me the reason why we cannot import urlparse from urllib.parse?

And I wonder if we can only execute all the command like create node, start the blockchain client under root? As it notify me "cannot import Crypto" when I type python blockchain_client.py without sudo.

Thanks.

How a new account gets coins?

How a new account gets coins? The miner should bind an account and transfer the mining rewards to this account. Isn't it?

No module named Crypto

$ python blockchain_client.py
Traceback (most recent call last):
File "blockchain_client.py", line 22, in
import Crypto
ImportError: No module named Crypto

sender address

Hi Adil,

Thanks for your codes! I learned a lot from it!
I have a small question. How to generate the sender and receiver address for the url such as http://127.0.0.1:5000?

Thanks

xwei

ModuleNotFoundError: No module named 'Crypto'

Hello, it doesn't work when executing the follow command in Windows 10+python3.6:

python blockchain.py -p 5000

The error information is:

ModuleNotFoundError: No module named 'Crypto'

Then, after installed crypto

pip install crypto

Another problem appears:

ModuleNotFoundError: No module named 'Crypto.Random'

Any pip package needed to install before ? If so, would you please append the requirement file ?
Thanks for your sharing!

I am not able to add node

can you please tell me ,what is the issue behind that .when i enter node address it was as it is.... nothing was changed

I am not able to transact the amount entered

Hi there I am new to blockchain development and learning it with your codes your codes are very useful in understanding blockchain but there one issue that i am not able to transact the amount in the make transactions page the success modal does not appear can anybody please help me with that

Blockchain Nodes are not sync

hi all
i run blockchain.py on 3 or 4 different port
in configure tab in every blockchain node i added another node addreses
but when i mine a block in for example node 1 when i press refresh button in every blockchain node Nothing happen and nodes are not sync

in addition i use win10 and i run it under Spyder
in spyder i have 4 console that every blockchain.py run at that console
and every thing work except node synnc

OrderedDict to string can change place for fields

Hi, on client side after print i have:
OrderedDict([('value', 1), ('sender_address', '30819f300d06092a864886f70d010101050003818d0030818902818100b5ee6802cd965cc6dae7f58e4ead61178f63435151bd2b828a04c2e67643161ecc855ddab5af5efa36b174edfa0a9b585ffcd989edf8255b8b2d92881a161b767129a742204d17e7df3eb51fc7e10887ad9e8ca519137e9fb3ddb1ca2e698a81784467dc9944b7e9688de552ea179e70612674d51c8decb9762fcb71f2fd4f950203010001'), ('recipient_address', '30819f300d06092a864886f70d010101050003818d0030818902818100b5ee6802cd965cc6dae7f58e4ead61178f63435151bd2b828a04c2e67643161ecc855ddab5af5efa36b174edfa0a9b585ffcd989edf8255b8b2d92881a161b767129a742204d17e7df3eb51fc7e10887ad9e8ca519137e9fb3ddb1ca2e698a81784467dc9944b7e9688de552ea179e70612674d51c8decb9762fcb71f2fd4f950203010001')])
on bitcoin side:
OrderedDict([('sender_address', '30819f300d06092a864886f70d010101050003818d0030818902818100b5ee6802cd965cc6dae7f58e4ead61178f63435151bd2b828a04c2e67643161ecc855ddab5af5efa36b174edfa0a9b585ffcd989edf8255b8b2d92881a161b767129a742204d17e7df3eb51fc7e10887ad9e8ca519137e9fb3ddb1ca2e698a81784467dc9944b7e9688de552ea179e70612674d51c8decb9762fcb71f2fd4f950203010001'), ('value', 1), ('recipient_address', '30819f300d06092a864886f70d010101050003818d0030818902818100b5ee6802cd965cc6dae7f58e4ead61178f63435151bd2b828a04c2e67643161ecc855ddab5af5efa36b174edfa0a9b585ffcd989edf8255b8b2d92881a161b767129a742204d17e7df3eb51fc7e10887ad9e8ca519137e9fb3ddb1ca2e698a81784467dc9944b7e9688de552ea179e70612674d51c8decb9762fcb71f2fd4f950203010001')])

as you can see dict value equals, but strings different as result verify return false.

Without P2P?

Hi, thank you for tutorial, how can i understand according implementation you can add nodes only in visible network?

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.