<p>Your input <code>txid</code> output index is 5 bytes, when it should be 4 bytes. Just remove the extra <code>00</code> byte and the transaction will not pop an error. However, you might need to sign this transaction again as signature involves signing the entire serialized transaction as a message and by changing the <code>txid</code> outpoint you will change the message that is signed.</p>

CC BY-SA 4.0
2019-07-17T15:42:32.240Z
Beat me to it :)
JBaczuk
CC BY-SA 4.0
2019-07-18T06:02:35.067Z
Yes. I could send to the network. Thanks @Ugam. My script key does not contain any keys. So I do not need to sign the tx with any keys. And for P2SH script address, I do not know how to derive the privatekey.
kitty
CC BY-SA 4.0
2019-07-18T06:13:35.107Z
@kitty Yes, since your `scriptSig` does not involve the use of any keys, it does not need to be changed.
Ugam Kamat
CC BY-SA 4.0
2019-07-17T15:38:59.503Z
2019-07-17T15:38:59.503Z
Ugam Kamat
<p>I have created a signature manually (referring the signature output formats in bitcoin-cli). But i tried to send the same to the network I am getting </p>

<p>error code: -22</p>

<p>error message:</p>

<p>TX decode failed</p>

<p>Below is the signed tx</p>

<p>signed tx:</p>

<p>020000000138c059adfe41e80fb46e14d23949304343abc560a6fbcef4b2e3110f8241816d00000000002c2b0768616e756d616ea8201ca35897540ec7ae7294a8cacd11caf2c09f95f026c925c6ce4e4c29b20e3c4187ffffffff0280507401000000001976a9146a3ffadddae4ccb4223a8c7215d4b481daf6967788ac00d012130000000017a914def347cf3b01bf03a30d7ee9f62d86ed5109b5478700000000</p>

<p>Spliting the same signed tx:</p>

<p>02 00 00 00  // version</p>

<p>01   // number of inputs (var_uint)</p>

<p>38 c0 59 ad fe 41 e8 0f b4 6e 14 d2 39 49 30 43 43 ab c5 60 a6 fb ce f4 b2 e3 </p>

<p>11 0f 82 41 81 6d  // input transaction hash</p>

<p>00 00 00 00 00 //  input index</p>

<p>2c // size of script (var_uint)</p>

<p>2b // data needs to be pushed  the below 43 bytes will be pushed </p>

<p>07 // push 7 bytes to stack</p>

<p>68 61 6e 75 6d 61 6e // data needs to be pushed</p>

<p>a8 // OP_HASH256 </p>

<p>20 // push 32 bytes</p>

<p>1c a3 58 97 54 0e c7 ae 72 94 a8 ca cd 11 ca f2 c0 9f 95 f0 26 c9 25 c6 ce 4e </p>

<p>4c 29 b2 0e 3c 41 </p>

<p>87 // OP_EQUAL</p>

<p>ff ff ff ff // sequence</p>

<p>02  // no of vouts</p>

<p>80 50 74 01 00 00 00 00 // amount</p>

<p>19 // size of script (var_uint) </p>

<p>76 //OP_DUP</p>

<p>a9 // OP_HAH160</p>

<p>14  // 20 bytes needs to be pushed</p>

<p>6a 3f fa dd da e4 cc b4 22 3a 8c 72 15 d4 b4 81 da f6 96 77 </p>

<p>88 // OP_EQUALVERIFY</p>

<p>ac //OP_CHECKSIG</p>

<p>00 d0 12 13 00 00 00 00 // amount</p>

<p>17 // size of script (var_uint) </p>

<p>a9 //  OP_HASH160</p>

<p>14 // 20 bytes needs to be pushed</p>

<p>de f3 47 cf 3b 01 bf 03 a3 0d 7e e9 f6 2d 86 ed 51 09 b5 47 </p>

<p>87 // OP_EQUAL</p>

<p>00000000 // lock time</p>

<p>Can anyone please help me to find what is that I am missing ?</p>

<bitcoin-core><bitcoind><script>
Bitcoin TX decode failed while sending to a the network(regtest)
kitty
# Bitcoin TX decode failed while sending to a the network(regtest)

(Asked by: username_0 on 2019-07-17)

I have created a signature manually (referring the signature output formats in bitcoin-cli). But i tried to send the same to the network I am getting

error code: -22

error message:

TX decode failed

Below is the signed tx

signed tx:

020000000138c059adfe41e80fb46e14d23949304343abc560a6fbcef4b2e3110f8241816d00000000002c2b0768616e756d616ea8201ca35897540ec7ae7294a8cacd11caf2c09f95f026c925c6ce4e4c29b20e3c4187ffffffff0280507401000000001976a9146a3ffadddae4ccb4223a8c7215d4b481daf6967788ac00d012130000000017a914def347cf3b01bf03a30d7ee9f62d86ed5109b5478700000000

Spliting the same signed tx:

02 00 00 00 // version

01 // number of inputs (var\_uint)

38 c0 59 ad fe 41 e8 0f b4 6e 14 d2 39 49 30 43 43 ab c5 60 a6 fb ce f4 b2 e3

11 0f 82 41 81 6d // input transaction hash

00 00 00 00 00 // input index

2c // size of script (var\_uint)

2b // data needs to be pushed the below 43 bytes will be pushed

07 // push 7 bytes to stack

68 61 6e 75 6d 61 6e // data needs to be pushed

a8 // OP\_HASH256

20 // push 32 bytes

1c a3 58 97 54 0e c7 ae 72 94 a8 ca cd 11 ca f2 c0 9f 95 f0 26 c9 25 c6 ce 4e

4c 29 b2 0e 3c 41

87 // OP\_EQUAL

ff ff ff ff // sequence

02 // no of vouts

80 50 74 01 00 00 00 00 // amount

19 // size of script (var\_uint)

76 //OP\_DUP

a9 // OP\_HAH160

14 // 20 bytes needs to be pushed

6a 3f fa dd da e4 cc b4 22 3a 8c 72 15 d4 b4 81 da f6 96 77

88 // OP\_EQUALVERIFY

ac //OP\_CHECKSIG

00 d0 12 13 00 00 00 00 // amount

17 // size of script (var\_uint)

a9 // OP\_HASH160

14 // 20 bytes needs to be pushed

de f3 47 cf 3b 01 bf 03 a3 0d 7e e9 f6 2d 86 ed 51 09 b5 47

87 // OP\_EQUAL

00000000 // lock time

Can anyone please help me to find what is that I am missing ?

**Tags:** bitcoin-core, bitcoind, script


---

## 1 answers

### Answer by username_1 on 2019-07-17. Score: 2

Your input `txid` output index is 5 bytes, when it should be 4 bytes. Just remove the extra `00` byte and the transaction will not pop an error. However, you might need to sign this transaction again as signature involves signing the entire serialized transaction as a message and by changing the `txid` outpoint you will change the message that is signed.

> **Comments:**
> **username_2**: Beat me to it :)  
> **username_0**: Yes. I could send to the network. Thanks @username_1. My script key does not contain any keys. So I do not need to sign the tx with any keys. And for P2SH script address, I do not know how to derive the privatekey.  
> **username_1**: @username_0 Yes, since your `scriptSig` does not involve the use of any keys, it does not need to be changed.  

---

