I'm trying to consolidate multiple inputs into a single output, all left over is for the miner.

When I send my transaction to a peer, it is never mined. I believe something is invalid in the multi-input signatures.

This is a sample input transaction for 1MeTVq6X8LCtcRDG4MNz1QVezxzxyffSTL:

in_transactions = []
txid = 
vout = 4
txin = CMutableTxIn(COutPoint(txid, vout))

This is how I create and validate signatures:

seckey = CBitcoinSecret("L1WIFKey...L1WIFKey")

# Create that scriptPubKey from scratch using the pubkey
# This is our signature to open each input
our_scriptPubKey = CScript([OP_DUP, OP_HASH160, Hash160(seckey.pub), OP_EQUALVERIFY, OP_CHECKSIG])

# Create the txout.
their_scriptPubKey = CBitcoinAddress(output_address).to_scriptPubKey()
txout = CMutableTxOut((btc_i_have - minner_fee) * COIN, their_scriptPubKey)

# Create the unsigned transaction.
# in_transactions is a list of [txin,txin,...]
tx = CMutableTransaction(in_transactions, [txout])

# Set the scriptSig of our transaction inputs appropriately.
for idx, txin in enumerate(in_transactions):
  sighash = SignatureHash(our_scriptPubKey, tx, idx, SIGHASH_ALL)
  sig = seckey.sign(sighash) + bytes([SIGHASH_ALL])
  txin.scriptSig = CScript([sig, seckey.pub])
  VerifyScript(txin.scriptSig, our_scriptPubKey, tx, idx, (SCRIPT_VERIFY_P2SH,))

# finally this is the raw transaction
raw_transaction = b2x(tx.serialize())

I wonder if I'm signing the inputs wrong when I do it one by one.

Thanks in advance.


The code works, the error is silent. The transaction was dropped silently by the network. It was a wrong transaction because one of my vout was pointing to a wrong output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.