Python coders, it’s time to start learning how to build Bitcoin transactions. Following the release of a Python SDK for the BSV blockchain, there are now some more detailed instructions for learning the basic steps to get things started.
nChain Senior Software Engineer Arthur Gordon published a beginner guide for Python devs on Medium. Much of the information will be familiar to those with existing Bitcoin experience, and for others, it’s a good refresher or a chance to open the hood and take a look at BSV’s inner workings to see what it’s capable of doing. The code in his article is also available as a Jupyter notebook.
Constructing transactions is a fundamental skill necessary to build more complex blockchain applications. To make it easier to practice without putting actual money at stake, BSV also has a Testnet and STN (Scaling Testnet) for experimenting. Just like the live Mainnet, the testnets also have block explorers where you can see what’s happening in real-time.
“As with most software engineering, being hands on helps build a deeper understanding of what is going on,” Gordon writes.
Some basic terms to familiarize yourself with here include “wallet keypair,” “block height,” and “TXID” (transaction ID number). The wallet keypair is the private-public key combination for sending and receiving transactions. Block height is the total number of blocks processed since Bitcoin began (currently about seven digits), and TXID is a (much longer) unique number for every transaction. Using a block explorer like WhatsOnChain, you can click on any block (height) number to see the transactions inside it and then look at the details on each TXID.
Gordon has provided instructions on which Python libraries to install and how to install them on your machine. PyPi’s tx-engine library can generate new wallets with their own unique keypairs. Copy the keys it generates, and remember to keep the private key secret.
The BSV Testnet has automated coin “faucets” with which you can fund the wallet’s using the public key (remember, this is just the testnet, so no actual Bitcoins are at risk). It’ll have its own TXID, which you can check to see if it received the funds—also, take note of the TXID number and the index of the “output” it sends to your address.
The first transaction you’ll construct is one to send the funds you received back to the faucet. The tx_engine contains classes to manually input the new data: inputs, outputs, fees, locking scripts, and signature. Gordon’s guide works through these processes step-by-step and describes what to do if your code returns errors.
Once the transaction you’ve built is complete, it’s time to broadcast it to the wider network (or at least the test network) and see if it works. If it does, it’ll be “mined” into a block, and you’ll see the results on the block explorer, with its own new TXID and complete with all the other details.
The guide is pretty easy to follow for anyone with basic programming knowledge, and naturally, you’ll need to understand how Python works to follow it completely. If you don’t have any Python experience, perhaps it’s time to get some. It’s one of the world’s most popular programming languages, is easier for absolute beginners to grasp, and is used in a growing number of applications (AI and blockchain being two of the fastest-spreading ones).
Also, if you’re not into Python specifically but would still like to learn the technical basics of Bitcoin, the BSV Academy has a series of online courses with quizzes and completion certificates. Those are available here.
Watch: Python SDK—essential tool for BSV developers
title=”YouTube video player” frameborder=”0″ allow=”accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share” referrerpolicy=”strict-origin-when-cross-origin” allowfullscreen>