Q
Q
qwwerty2020-08-31 17:42:04
bitcoin
qwwerty, 2020-08-31 17:42:04

Library/framework for working with Bitcoin transactions in Python?

Good day, I'm looking for a library for Python 3.x, with which I could create and sign BTC transactions.

You need a library that supports SegWit addresses in Bech32 encoding.
Namely, to support three Bitcoin address formats: P2PKH, P2SH, P2WPKH (Bech32).

Sample code I need:

import some_libary

inputs = {
    # btc_addr: private_key
    'bc1qayxpas47nrljgkkcuvx0kfyjpj9edh0ch6k3j2': 'L2aiRXYVbn95jFdjsMzcHvD4JG9Edf1Z1v9gvQEip4fN4i2yWwcc' 
}

outputs = {
    # btc_addr:  value (satoshi)
    '3JXRVxhrk2o9f4w3cQchBLwUeegJBj6BEp': 1000000, 
    'bc1qayxpas47nrljgkkcuvx0kfyjpj9edh0ch6k3j2': 21000000  # Сдача
}

tx = some_libary.mktx(ins=list(inputs.keys()), outs=outputs)
signed_tx = some_libary.signtx(tx, priv_keys=list(inputs.values()))
tx_hash = some_libary.pushtx(signed_tx)

print('TX ID:', tx_hash)


Vitalik Buterin's library - pybitcointools (after the termination of support - cryptos ) would suit me, but as I understand it, it does not support Bech32 encoded addresses.

I would be glad if they help me and provide a working code snippet similar to mine, if possible.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Q
qwwerty, 2020-09-06
@qwwerty

One of the best options is python-bitcoin-utils .
I also recommend cryptos for analyzing Bitcoin transactions and other useful features.

D
Dimonchik, 2020-08-31
@dimonchik2013

nothing better than bitcoind and its PRC interface have been invented

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question