During the fall semester of 2018 I have been taking an online course at University West named “Bitcoin och blockchain technology and theory with Python”.
We have been using Bitcoin RPC API (Yep, I know a lot of APIs for me) to retrieve info about the blockchain. You can also make raw transactions and then sign and send all through python code.
The first python assignment was to set up a Bitcoin Core Wallet. Using the Bitcoin RPC API to display information about the blockchain and blocks, transactions and addresses.
The second assignment was to get familiar with how cryptography and bitcoin transactions. Generating private keys, public keys and creating raw transactions and sign and send them.The cryptography in Bitcoin uses Elliptic Curve Digital Signature Algorithm (ECDSA) and double sha256. Since the random numbers generated in programming languages actually are not truly random there are other methods to use when randomizing private keys. Here is the classmethod I wrote in python for this assignment using the os.urandom() method.
@classmethod
def genPrivateKey(cls):
priv_key = os.urandom(32)
priv_key = (int.from_bytes(priv_key, byteorder='big') % 1000000)
return priv_key
The last assignment was to build a bitcoin miner. Building the blockheader and coinbase transaction from bytes and hexadecimal.