A python implementation of an offline Bitcoin Cash transaction
Prerequisite
Only the BitCash python libraries are needed. BitCash is a powerful python library for the Bitcoin Cash (BCH) network that neatly encapsulates a lot of the blockchain development complexities. It was inspired by Requests and Keras, and was forked from the Bitcoin (BTC) 'Bit' python library.
If you're unfamiliar with BitCash please checkout Corentin Mercier's guide.
Install the BitCash python libraries
pip install bitcash
Offline Transaction Demo
- Clone the repo
git clone https://github.com/fifikobayashi/Offline-BCH-Transaction
- Update the transaction parameters in build_tx.py such as transfer currency, amount, target address... etc
# Transaction parameters
transferCurrency = 'bch'
transferAmount = 0.0001
txDataFile = 'offlineTxData.json'
txHexFile = 'offlineTxHex.json'
receivingAddress = 'n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi'
- Run build_tx.py which will take in the transaction parameters and generate a offlineTxData.JSON file
python3 build_tx.py
-
The sign_tx() function within build_tx.py simulates the physical step of taking the generated tx data JSON file to, say, an air-gapped terminal or to an area in Africa with no internet access. The function reads the JSON file, signs the transaction and writes the output to a offlineTxHex.JSON file.
-
Run broadcast_tx.py which will take in the tx hex JSON generated by sign_tx() and broadcasts it onto the BCH network.
python3 broadcast_tx.py
- Lookup the sending address on the BCH testnet explorer to verify it has been added to the mempool.