0

I'm developing transaction constructor, but i faced several problems. To some of which i found answer in How to sign a transaction with multiple inputs?, for the rest i'll try to explain:

  1. When we have multiple inputs and multiple outputs and try to sign every input what do we fill in the output value section for each one of them: The total sum of the transaction inputs or the corresponding amount that every input that we sign has and we distribute between the outputs?

'version': 1, 'inputs': (2) { 'output_tx_hash': 'aaaa', 'output_position': 0, 'script': the original script, like: '76a914' + hash + '88ac', 'sequence': ffffffff, }, { 'output_tx_hash': 'bbbb', 'output_position': 1, 'script': '', # Nothing 'sequence': ffffffff, } 'outputs': (2) 'value' : 100000 'script' : '76a914' + hash of btc pub key + '88ac' 'value' : 50000 'script' : '76a914' + hash of btc pub key + '88ac' 'locktime': 0

  1. In the section script in inputs, there is "Nothing", but what is the exact byte count of it - 1 byte, 4 bytes or something else?
  2. Is there a step-by-step guide or tutorial for manual transaction building and signing that covers multiple inputs and multiple outputs transaction. I successfully send transactions to the blockchain but only the ones with one input.
0

When we have multiple inputs and multiple outputs and try to sign every input what do we fill in the output value section for each one of them: The total sum of the transaction inputs or the corresponding amount that every input that we sign has and we distribute between the outputs?

For non-segwit inputs, the message that is hashed for you to sign is almost the entire transaction itself. You must have all of the outputs in the order that they will be in in the final transaction. You don't put one output or aggregate them - you put all of them as if it were the final transaction.

For segwit inputs, instead of putting all of the outputs in the message, you first hash them all together. They are serialized as if they were going to be in a transaction, then hashed all at once. The resulting SHA256 hash is what you use in the message. Read BIP 143 for more information about that. The value field in that message is the value of just the output that is spent by that particular input.

In the section script in inputs, there is "Nothing", but what is the exact byte count of it - 1 byte, 4 bytes or something else?

"Nothing" means that there is a script of length 0, so it means the single byte 00. However, at no point in transaction signing are you ever signing an empty script. If you are, something is wrong.

  • So for example if I have 5 inputs, I need to sign each input individually placing the sigScript for the one that we sign and one byte 00 as you say for the others, and I repeat that step 5 times - for each input? – Dimitar Vasilev Jun 11 at 10:01
  • @DimitarVasilev Yes. – Andrew Chow Jun 11 at 15:39

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.