Git Product home page Git Product logo

python-blockchain-tutorial's Introduction

Python, JS, & React | Build a Blockchain & Cryptocurrency

Course Logo

The course is designed to help you achieve three main goals:

  • Learn Python and Backend Web Development.
  • Build a Blockchain and Cryptocurrency Project that you can add to your portfolio.
  • Learn JavaScript, Frontend Web Development, React.js, and React Hooks.

The course's main project is to build a blockchain and cryptocurrency. With a blockchain and cryptocurrency system as the main goal, you will go through a course journey that starts with backend development using Python. Then, you will transaction to frontend web development with JavaScript, React.js, and React Hooks.

Check out the course: https://www.udemy.com/course/python-js-react-blockchain/?referralCode=9051A01550E782315B77

Here's an overview of the overall course journey:

  • Get an introduction of the Python Fundamentals.
  • Begin building the Blockchain Application with Python.
  • Test the Application using Pytest.
  • Incorporate the crucial concept of Proof of Work into the Blockchain.
  • Enhance the application to prepare for networking.
  • Create the Blockchain network using Flask and Pub/Sub.
  • Integrate the Cryptocurrency, building Wallets, Keys, and Transactions.
  • Extend the network implementation with the cryptocurrency.
  • Transition from Python to JavaScript with a "From Python to JavaScript" introduction.
  • Establish frontend web development skills and begin coding with React.js.
  • Create the frontend portion for the blockchain portion of the system.
  • Complete the frontend by building a UI for the cryptocurrency portion of the system.

In addition, here are the skills that you'll gain from the course:

  • How to build a blockchain and cryptocurrency system from scratch.
  • The fundamentals of python - data structures, object-oriented programming, modules, and more.
  • The ins and outs of hashing and sha256.
  • Encoding and decoding in utf-8.
  • Testing Python applications with pytest.
  • Python virtual environments.
  • The concept of proof of work, and how it pertains to mining blocks.
  • Conversion between hexadecimal to binary.
  • HTTP APIs and requests.
  • How to create APIs with Python Flask.
  • The publish/subscribe pattern to set up networks.
  • When to apply the concepts of serialization and deserialization.
  • Public/private keypairs and generating data signatures.
  • The fundamentals of JavaScript.
  • Frontend web development and how web applications are constructed.
  • The core concepts of React and React hooks.
  • How the React engine works under the hood, and how React applies hooks.
  • CORS - and how to get over the CORS error properly.
  • How to build a pagination system.

Command Reference

Activate the virtual environment

source blockchain-env/bin/activate

Install all packages

pip3 install -r requirements.txt

Run the tests

Make sure to activate the virtual environment.

python3 -m pytest backend/tests

Run the application and API

Make sure to activate the virtual environment.

python3 -m backend.app

Run a peer instance

Make sure to activate the virtual environment.

export PEER=True && python3 -m backend.app

Run the frontend

In the frontend directory:

npm run start

Seed the backend with data

Make sure to activate the virtual environment.

export SEED_DATA=True && python3 -m backend.app

python-blockchain-tutorial's People

Contributors

15dkatz 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

python-blockchain-tutorial's Issues

403 error with default ROOT_PORT 5000

Hey,
I stumbled upon a problem with the default port 5000 on macOS Ventura (13.6.1).
In chapter 7.13 of the tutorial I get with:


while starting up a second node:

export PEER=True && python3 -m backend.app

as requests.get result:

result: <Response [403]>

I found out (through stackoverflow) that macOS uses this port with the control center. It can be fixed by setting ROOT_PORT to some other value than 5000.

Great tutorial and maybe this info is of use to someone else!
Cheers

Need some reference

If i want to implement this on a p2p network, what will be the best way to implement that?

bug in app/__init__.py allows miners to get rewards when the transaction pool is empty

Currently, the code to mine a block looks like this:

@app.route('/blockchain/mine')
def route_blockchain_mine():
  transaction_data = transaction_pool.transaction_data()
  transaction_data.append(Transaction.reward_transaction(wallet).to_json())
  blockchain.add_block(transaction_data)
  block = blockchain.chain[-1]
  pubsub.broadcast_block(block)
  transaction_pool.clear_blockchain_transactions(blockchain)

  return jsonify(block.to_json())

The problem here is that going to the /blockchain/mine endpoint causes the system to create a mining reward transaction even with an empty transaction pool. So a miner could keep hitting this endpoint over and over to get free coins.

The fix I made was to check and make sure there is a transaction to mine before handing out a mining reward; if the transaction pool is empty, the endpoint sends back a JSON message informing the miner that the transaction pool is empty.

@app.route('/blockchain/mine')
def route_blockchain_mine():
  transaction_data = transaction_pool.transaction_data()
  if transaction_data:
    transaction_data.append(Transaction.reward_transaction(wallet).to_json())
    blockchain.add_block(transaction_data)
    block = blockchain.chain[-1]
    pubsub.broadcast_block(block)
    transaction_pool.clear_blockchain_transactions(blockchain)

    return jsonify(block.to_json())
  return {"message": "Transaction pool is empty"}

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.