<p>What is the procedure to sign a raw transaction with multiple inputs, i have some doubts, this is what i am doing:</p>

<p><strong>Step 1</strong>
First I serialize 1 unsigned tx for each input.</p>

<pre><code>INPUT 1

02000000 // Version
02 //In Count
d444d165b2aa04fcf9074eb1a0e5b6d528663a80d1732092f5a62fbdb175378c
00000000
19 // Sig Length
76a914c29b169112aa249e5ada916d8e259ed7d16cf58688ac // Temporary Sig
ffffffff
f6dd8d85c831a2f196cc5e4c43792bf25a6d2b119d59b8f430edaa8d20dedc5c
00000000
00 //Empty Sig
ffffffff
02
7485010000000000
19
76a91451e9f768d4ca9a7a36084b0138a154d0b98b53c688ac
6400000000000000
19
76a91451e9f768d4ca9a7a36084b0138a154d0b98b53c688ac
00000000
01000000

INPUT 2

02000000
02
d444d165b2aa04fcf9074eb1a0e5b6d528663a80d1732092f5a62fbdb175378c
00000000
00 // Empty Sig
ffffffff
f6dd8d85c831a2f196cc5e4c43792bf25a6d2b119d59b8f430edaa8d20dedc5c
00000000
19
76a914c29b169112aa249e5ada916d8e259ed7d16cf58688ac //Temporary Sig
ffffffff
02
7485010000000000
19
76a91451e9f768d4ca9a7a36084b0138a154d0b98b53c688ac
6400000000000000
19
76a91451e9f768d4ca9a7a36084b0138a154d0b98b53c688ac
00000000
01000000
</code></pre>

<p><strong>Step 2</strong> For each input, i double sha256 and then reverse it.</p>

<p><strong>Step 3</strong> I sign each hash:</p>

<pre><code>6b4830450221008d998e1d6c91ef14d76934a818731d58328ad97ed2c78f092d86750da5d28635022013d827ca2ab96bd8e7f069cffb6b80def6f4243a9dcca54e730de5d05306d03e0121036bc7427b751bd05d172178dbe3193f02a57615cdd8e079ad46bde44b5a96379e

6a47304402202569958de7a0d45052e651ed7b5c97b8d6bb04deef5d588099026a1298a18a0802204339ae2438436b2d90cdbd41cd1d19028ddfc8eaa490298e0a1c93d33da608640121036bc7427b751bd05d172178dbe3193f02a57615cdd8e079ad46bde44b5a96379e
</code></pre>

<p><strong>Step 4</strong> I serialize the final Transaction:</p>

<pre><code>02000000
02
d444d165b2aa04fcf9074eb1a0e5b6d528663a80d1732092f5a62fbdb175378c
00000000
6b
4830450221008d998e1d6c91ef14d76934a818731d58328ad97ed2c78f092d86750da5d28635022013d827ca2ab96bd8e7f069cffb6b80def6f4243a9dcca54e730de5d05306d03e0121036bc7427b751bd05d172178dbe3193f02a57615cdd8e079ad46bde44b5a96379e
ffffffff
f6dd8d85c831a2f196cc5e4c43792bf25a6d2b119d59b8f430edaa8d20dedc5c
00000000
6a
47304402202569958de7a0d45052e651ed7b5c97b8d6bb04deef5d588099026a1298a18a0802204339ae2438436b2d90cdbd41cd1d19028ddfc8eaa490298e0a1c93d33da608640121036bc7427b751bd05d172178dbe3193f02a57615cdd8e079ad46bde44b5a96379e
ffffffff
02
7485010000000000
19
76a91451e9f768d4ca9a7a36084b0138a154d0b98b53c688ac
6400000000000000
19
76a91451e9f768d4ca9a7a36084b0138a154d0b98b53c688ac
00000000
</code></pre>

<p><strong><em>The problem that I have</em></strong></p>

<p>I get this when broadcasting the <code>TX: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)</code></p>

<p>What I am doing wrong?, should i put the SigHashType at the bottom of each TX <code>01000000</code>, exactly what i need to put on the Temporary Sig, i am putting my Script Public Key Hash</p>

CC BY-SA 4.0
2020-04-02T12:45:03.140Z
Start by removing "Timestamp" bytes, they don't exist in a transaction!
Coding Enthusiast
CC BY-SA 4.0
2020-04-02T17:45:18.133Z
I forget to mention that i am using a Bitcoin fork that has timestamp (Emercoin), but it should work the same as Bitcoin, i already get working a single input TX. But i will remove it on this post to dont cause confusion, thanks
Fabricio Espinoza
CC BY-SA 4.0
2020-04-03T03:22:34.437Z
Your second step is also strange, we don't reverse SHA256 result before signing.
Coding Enthusiast
CC BY-SA 4.0
2020-04-06T21:11:27.240Z
This is what i was doing wrong thank you very much, post this answer to give you the reputation if you want!
Fabricio Espinoza
<bitcoin-core><blockchain><bitcoind><client>
How to sign Raw Transaction with Multiple Inputs
Fabricio Espinoza
# How to sign Raw Transaction with Multiple Inputs

(Asked by: username_0 on 2020-04-01)

What is the procedure to sign a raw transaction with multiple inputs, i have some doubts, this is what i am doing:

**Step 1**
First I serialize 1 unsigned tx for each input.

```
INPUT 1

02000000 // Version
02 //In Count
d444d165b2aa04fcf9074eb1a0e5b6d528663a80d1732092f5a62fbdb175378c
00000000
19 // Sig Length
76a914c29b169112aa249e5ada916d8e259ed7d16cf58688ac // Temporary Sig
ffffffff
f6dd8d85c831a2f196cc5e4c43792bf25a6d2b119d59b8f430edaa8d20dedc5c
00000000
00 //Empty Sig
ffffffff
02
7485010000000000
19
76a91451e9f768d4ca9a7a36084b0138a154d0b98b53c688ac
6400000000000000
19
76a91451e9f768d4ca9a7a36084b0138a154d0b98b53c688ac
00000000
01000000

INPUT 2

02000000
02
d444d165b2aa04fcf9074eb1a0e5b6d528663a80d1732092f5a62fbdb175378c
00000000
00 // Empty Sig
ffffffff
f6dd8d85c831a2f196cc5e4c43792bf25a6d2b119d59b8f430edaa8d20dedc5c
00000000
19
76a914c29b169112aa249e5ada916d8e259ed7d16cf58688ac //Temporary Sig
ffffffff
02
7485010000000000
19
76a91451e9f768d4ca9a7a36084b0138a154d0b98b53c688ac
6400000000000000
19
76a91451e9f768d4ca9a7a36084b0138a154d0b98b53c688ac
00000000
01000000

```

**Step 2** For each input, i double sha256 and then reverse it.

**Step 3** I sign each hash:

```
6b4830450221008d998e1d6c91ef14d76934a818731d58328ad97ed2c78f092d86750da5d28635022013d827ca2ab96bd8e7f069cffb6b80def6f4243a9dcca54e730de5d05306d03e0121036bc7427b751bd05d172178dbe3193f02a57615cdd8e079ad46bde44b5a96379e

6a47304402202569958de7a0d45052e651ed7b5c97b8d6bb04deef5d588099026a1298a18a0802204339ae2438436b2d90cdbd41cd1d19028ddfc8eaa490298e0a1c93d33da608640121036bc7427b751bd05d172178dbe3193f02a57615cdd8e079ad46bde44b5a96379e

```

**Step 4** I serialize the final Transaction:

```
02000000
02
d444d165b2aa04fcf9074eb1a0e5b6d528663a80d1732092f5a62fbdb175378c
00000000
6b
4830450221008d998e1d6c91ef14d76934a818731d58328ad97ed2c78f092d86750da5d28635022013d827ca2ab96bd8e7f069cffb6b80def6f4243a9dcca54e730de5d05306d03e0121036bc7427b751bd05d172178dbe3193f02a57615cdd8e079ad46bde44b5a96379e
ffffffff
f6dd8d85c831a2f196cc5e4c43792bf25a6d2b119d59b8f430edaa8d20dedc5c
00000000
6a
47304402202569958de7a0d45052e651ed7b5c97b8d6bb04deef5d588099026a1298a18a0802204339ae2438436b2d90cdbd41cd1d19028ddfc8eaa490298e0a1c93d33da608640121036bc7427b751bd05d172178dbe3193f02a57615cdd8e079ad46bde44b5a96379e
ffffffff
02
7485010000000000
19
76a91451e9f768d4ca9a7a36084b0138a154d0b98b53c688ac
6400000000000000
19
76a91451e9f768d4ca9a7a36084b0138a154d0b98b53c688ac
00000000

```

***The problem that I have***

I get this when broadcasting the `TX: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)`

What I am doing wrong?, should i put the SigHashType at the bottom of each TX `01000000`, exactly what i need to put on the Temporary Sig, i am putting my Script Public Key Hash

**Tags:** bitcoin-core, blockchain, bitcoind, client

> **Comments:**
> **username_1**: Start by removing "Timestamp" bytes, they don't exist in a transaction!  
> **username_0**: I forget to mention that i am using a Bitcoin fork that has timestamp (Emercoin), but it should work the same as Bitcoin, i already get working a single input TX. But i will remove it on this post to dont cause confusion, thanks  
> **username_1**: Your second step is also strange, we don't reverse SHA256 result before signing.  
> **username_0**: This is what i was doing wrong thank you very much, post this answer to give you the reputation if you want!  

---

## 0 answers

