RADIX WikiRADIX Wiki
Connecting...

A basic implementation of the Proof of Work (PoW) algorithm used as Sybil prevention by Bitcoin and other PoW networks. A deeper comparison between PoW and Proof of Stake (PoS) can be found in our article PoW vs PoS: The Next Industrial Revolution.

Method & Python Script

  1. Install VS Code: https://code.visualstudio.com or similar application.

  2. In VS Code open a new terminal window by navigating to Terminal > New Terminal.

  3. Install Homebrew by pasting the following code into the terminal and pressing Enter:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  4. Install Python in the same way:

    brew install python
  5. Next, install the modules that the script needs (dependencies):

    pip3 install hashlib datetime
  6. Now, create a project folder and navigate to it in VS Code via File > Open Folder.

  7. Create a new Python file in VS Code via File > New File. Name it something like pow.py

  8. This script calculates the hash for the text “hello” with five leading zeros. Copy and paste it into pow.py and save it.

# v.0.1

from hashlib import sha256
from datetime import datetime

def pow(data, zeros, nonce):
    data = str(data).encode("utf-8")
    zeros = zeros * "0"

    t1 = datetime.now()
    while True:
        combo = data + f"{nonce}".encode("utf-8")
        hash_ = sha256(combo).hexdigest()
        if hash_.startswith(zeros):
            t2 = datetime.now()
            return nonce, hash_, t2-t1
        else:
            nonce += 1

output = pow("hello", 5, 0) # 5 = ~ 1 second
print(output)
  1. Run the script from the terminal with:

python3 pow.py

Connect your wallet to join the discussion.