Simple Bitcoin cryptography implementation that generates BTC addresses from scratch and sends custom transactions with Bitcoin Core RPC.
🎥 Featured in my YouTube video: https://youtu.be/z2Ju7pcE6wo
-
Address Generation (
main.ipynb): Generate Bitcoin addresses from private keys using secp256k1- Legacy addresses (P2PKH)
- SegWit addresses (Bech32)
- Private key formats: decimal, hex, WIF
-
Transaction Sending (
send.ipynb): Send Bitcoin with custom messages via Bitcoin Core RPC- OP_RETURN data embedding
- PSBT workflow
-
Install dependencies:
pip install -r requirements.txt
-
For transaction sending, create
.envfile:RPC_USER=your_username RPC_PASSWORD=your_password RPC_HOST=127.0.0.1 RPC_PORT=8332
-
Run the notebooks:
main.ipynb- Generate Bitcoin addressessend.ipynb- Send transactions (requires Bitcoin Core)
After generating addresses, you can import them to Bitcoin Core to monitor transactions:
-
Get descriptor info - Open Bitcoin Core console and run:
getdescriptorinfo "combo(WIF)"Example:
getdescriptorinfo "combo(Kz6dh8Ny4HuCDrWEsyBZsUUjz16ab1hmgR5ihvKFx7wGGFibe7Cc)"Response:
{ "descriptor": "combo(02ffd6ef90a5bb4ca138aaad516560aa80157ae0629a27099660dfd5039bc3fa2b)#l3la8e8y", "checksum": "04fk0myz", "isrange": false, "issolvable": true, "hasprivatekeys": true } -
Import the descriptor - Use the descriptor with checksum:
importdescriptors '[{"desc": "combo(WIF)#DESCRIPTOR", "timestamp": "now"}]'Example:
importdescriptors '[{"desc": "combo(02ffd6ef90a5bb4ca138aaad516560aa80157ae0629a27099660dfd5039bc3fa2b)#l3la8e8y", "timestamp": "now"}]'
Note: The timestamp parameter determines when to start scanning for transactions:
"now"- Only scan for new transactions from current time0- Scan from the beginning of the blockchain (full rescan)- Unix timestamp - Scan from a specific date (e.g.,
1640995200for Jan 1, 2022)
The descriptor format includes the checksum after the # symbol for verification.
ecdsa- Elliptic curve cryptographybase58- Address encodingbech32- SegWit address encodingbitcoinrpc- Bitcoin Core RPC client