I am making an attempt to ship a reasonably easy segwit transaction with a number of enter and outputs utilizing bitcoinlib, here is how the simplified code seems like:
from bitcoinlib.transactions import Output, Key, Transaction
# (prev_txid, output_n, tackle, worth in satoshis)
inputs = [
(u'4ab923ee400a3899dc0790c7658af9931e54fc40dc1a8a79281a989e6a56ddd2', 125, 'bc1p0val59xpljwfr52hdg667v0nnnjzusfmvgys6warv7hklrfjum7sjgj75j', 1077938),
]
outputs = []
outputs.append(Output(15260, tackle="bc1pylrxedd66287hl0e000qy9c86u9tagg206yvyymp4j2c6c5npfjseyjpdu"))
# 1000 = 10.00 sat/vB
fee_per_kb = 1000
t = Transaction(outputs=outputs, witness_type="segwit", model=2)
for ti in inputs:
ki = Key("PRIVATE_KEY")
t.add_input(prev_txid=ti[0], output_n=ti[1], tackle=ti[2], worth=ti[3], keys=ki.public(), witness_type="segwit")
charge = spherical((t.estimate_size(1) * fee_per_kb) / 100)
total_inputs = 0
for ti in inputs:
total_inputs += ti[3]
total_output = 15260
change = total_inputs - total_output - charge
# Add change output
t.add_output(change, tackle="bc1pyr9x8f7z5t9cxykfzzx66y2xc3davshzmd3xmf9dcxdpkg4tjuusschhpq")
icount = 0
for ti in inputs:
ki = Key("PRIVATE_KEY")
t.signal(ki.private_byte, icount)
icount += 1
t.update_totals()
t.confirm()
t.information()
print()
print("Uncooked Signed Transaction: %s" % t.raw_hex())
Transaction b2b765f26c3d8f766e205f1ae4bd82950f6283013ed23c0dd6d337c15b30d97a
Date: None
Community: bitcoin
Model: 2
Witness sort: segwit
Standing: new
Verified: True
Inputs
- bc1p0val59xpljwfr52hdg667v0nnnjzusfmvgys6warv7hklrfjum7sjgj75j 0.01077938 BTC 4ab923ee400a3899dc0790c7658af9931e54fc40dc1a8a79281a989e6a56ddd2 125
segwit sig_pubkey; sigs: 1 (1-of-1) legitimate
Outputs
- bc1pylrxedd66287hl0e000qy9c86u9tagg206yvyymp4j2c6c5npfjseyjpdu 0.00015260 BTC p2tr U
- bc1pyr9x8f7z5t9cxykfzzx66y2xc3davshzmd3xmf9dcxdpkg4tjuusschhpq 0.01061148 BTC p2tr U
Measurement: 236
Vsize: 153
Payment: 1530
Confirmations: None
Block: None
Uncooked Signed Transaction: 02000000000101d2dd566a9e981a28798a1adc40fc541e93f98a65c79007dc99380a40ee23b94a7d00000000ffffffff029c3b00000000000022512027c66cb5bad28febfdf97bde021707d70abea10a7e88c21361ac958d62930a651c3110000000000022512020ca63a7c2a2cb8312c9108dad1146c45bd642e2db626da4adc19a1b22ab973902473044022019d43d372c8d6967f377f76d20a24d31fb3cb046a5640e9a02197afa526738dd02201afdc3e421665b35397ef2adf40908aeb3031569e49aab367285a9015effbd1f0121023f5bdab1fb426681f1a020998ffc69c844f380fe6e0d67b73e7fc9bc3291018b00000000
Every little thing appears okay when working the script and it even reveals Verified
as True
however when I attempt to ship it by way of bitcoin-cli I get a “non-mandatory-script-verify-flag (Witness program hash mismatch)” error.
I feel I am making a mistake signing my inputs however I am undecided how, I checked the personal key a number of instances and it does match the tackle that presently holds the UTXO.
Can anybody advise what to do?