Skip to content

Instantly share code, notes, and snippets.

@maxweisspoker
Last active March 15, 2024 13:16
Show Gist options
  • Save maxweisspoker/4eb6e11dac44ea02216eb222f99c9985 to your computer and use it in GitHub Desktop.
Save maxweisspoker/4eb6e11dac44ea02216eb222f99c9985 to your computer and use it in GitHub Desktop.
Python script to download the bitcoin whitepaper directly from the blockchain itself.
#!/usr/bin/env python
# This script is a modified version of the script found here:
# https://bitcoin.stackexchange.com/questions/35959/how-is-the-whitepaper-decoded-from-the-blockchain-tx-with-1000x-m-of-n-multisi
from __future__ import print_function
import subprocess
import sys
from binascii import unhexlify
from hashlib import sha256
if int(sys.version[0]) == 2: # Works with older version of Python
from urllib2 import urlopen
else:
from urllib.request import urlopen
save_file = "bitcoin.pdf"
# Do not change this!
whitepaper_txid = "54e48e5f5c656b26c3bca14a8c95aa583d07ebe84dde3b7dd4a78f4e4186e713"
try:
#raw = urlopen("https://blockchain.info/tx/" + whitepaper_txid + "?format=hex").read()
raw = subprocess.check_output(["bitcoin-cli", "getrawtransaction", whitepaper_txid])
assert sha256(sha256(unhexlify(raw)).digest()).digest() == unhexlify(whitepaper_txid)[::-1]
except:
print("Error retrieving bitcoin transaction which contains the pdf data. Exiting...", file=sys.stderr)
sys.exit(1)
if int(sys.version[0]) == 2:
outputs = raw.split("0100000000000000")
pdf = ""
else:
outputs = raw.split(b"0100000000000000")
pdf = b""
for output in outputs[1:-2]:
cur = 6
pdf += unhexlify(output[cur:cur+130])
cur += 132
pdf += unhexlify(output[cur:cur+130])
cur += 132
pdf += unhexlify(output[cur:cur+130])
pdf += unhexlify(outputs[-2][6:-4])
with open(save_file, "wb") as f:
f.write(pdf[8:-8])
@VincentKaufmann
Copy link

Hello Max, Your script stopped working.
Cheers, Vince
Error retrieving bitcoin transaction which contains the pdf data. Exiting...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment