---
title: "Proof of Work"
path: "/contents/resources/python-scripts/proof-of-work"
version: "1.2.1"
author: "Hydrate"
createdAt: "2026-01-27T11:53:54.804Z"
updatedAt: "2026-07-20T21:40:53.985Z"
---

# Proof of Work

<Infobox>
| Type | Python script · worked example |
| Demonstrates | SHA-256 hash mining as Sybil prevention |
| Language | Python 3 |
| Dependencies | None — [hashlib](https://docs.python.org/3/library/hashlib.html) and [datetime](https://docs.python.org/3/library/datetime.html) ship with Python |
| Difficulty | Tunable via leading-zero count (5 ≈ 1 second) |
| Related | [PoW vs PoS](/blog/pow-vs-pos-the-next-industrial-revolution) · [Delegated Proof of Stake](/contents/tech/core-concepts/delegated-proof-of-stake-dpos) · [DLT Efficiency Metric](/contents/resources/python-scripts/dlt-efficiency-metric) |


</Infobox>

A basic implementation of the Proof of Work (PoW) algorithm used as Sybil prevention by [Bitcoin](https://bitcoin.org) 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**](/blog/pow-vs-pos-the-next-industrial-revolution).

## **Method & Python Script**

1. $1
2. $1
3. $1
4. $1
5. $1
6. $1
7. $1
8. $1

```python
# 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. $1
`python3 pow.py`