Last active
December 25, 2021 12:42
-
-
Save gdassori/91a73d194100e4b009a48a5124d4c75b to your computer and use it in GitHub Desktop.
Easy proof of existence with Bitcoin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Proof of existence \ Blockchain Graffiti | |
import hashlib | |
import bitcoin # http://github.com/conio/pybitcointools <- this is this dependency | |
key = hashlib.sha256(b'Change me! I am your private key').digest() # Set your private key | |
address = bitcoin.privtoaddr(key) | |
print('\nDeposit Bitcoin here:\n%s\n' % address) | |
# The amount of the incoming transaction | |
AMOUNT_BTC = 0.001 | |
# The message you're going to write in blockchain (or the hash of the file you wish to prove the existence) | |
MESSAGE = b'Hi, I am a message in the blockchain! Script by twitter.com/khs9ne' | |
# Subtract the fee, the transaction would be around 200~250 bytes. If you are *VERY HURRY* | |
# estimate 300 bytes and we're ok. | |
# Use the current fee per byte, you can see it here: https://bitcoinfees.earn.com/ | |
FEE_PER_BYTE_SATOSHI = 10 | |
TX_SIZE = 300 | |
FEE_SATOSHI = TX_SIZE * FEE_PER_BYTE_SATOSHI | |
# Edit here the money destination address (where to take back the money sent previously) | |
# Leave this address to tip me :-) | |
DESTINATION_ADDRESS = '3FVGopUDc6tyAP6t4P8f3GkYTJ5JD5tPwV' | |
# Once you have money on the address, put here the unspent coordinates | |
OUTPOINT = 'b1a132ce3b6f42263b2a8ce87014499ff6542dff1df2dc19cadd8ec9caa7ec93:2' | |
outpoints = [ | |
{ | |
'output': OUTPOINT, | |
'value': int(AMOUNT_BTC * 10**8) | |
} | |
] | |
tx = bitcoin.mktx( | |
outpoints, | |
[ | |
{'value': (int(AMOUNT_BTC * 10**8)) - FEE_SATOSHI, 'address': DESTINATION_ADDRESS }, | |
] | |
) | |
tx = bitcoin.mk_opreturn(MESSAGE, tx) | |
tx = bitcoin.sign(tx, 0, key) | |
print('Transaction to broadcast:\n%s' % tx) | |
# Here is printed the transaction to be broadcast. You can use this API to send it https://blockstream.info/tx/push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment