<p>Your redeem script has the length of the script prepended to it (<code>2d</code>), which causes the stack execution to finalize with the redeem script in the stack as data instead of interpreting it as another script.</p>
<p>The script interprets the <code>2d</code> as if you intended to put data in the stack with a length of 45 bytes, instead of actually interpreting your redeem script as a script. Therefore, Your redeem script must start with <code>52</code> and not the legth of the script which is 0x2d.</p>
<p>After you delete the <code>2d</code> from the redeem script, sign the tx again since this extra byte also changes the whole tx to sign.</p>
<p>Also, if you used that redeem script to compute your p2sh address, it is possible that you sent the money to the wrong address.</p>

CC BY-SA 4.0
2021-03-01T22:54:34.087Z
It is funny while searching for help online I stumbled upon one of your question from here, Im gonna change my code then do the whole process again as you advise, luckily thats not real bitcoins
Saxtheowl
CC BY-SA 4.0
2021-03-02T03:53:23.650Z
lol nice. Let me know how it goes.
Oscar Serna
CC BY-SA 4.0
2021-03-01T22:42:39.347Z
2021-03-01T22:42:39.347Z
Oscar Serna
<p>I have <a href="https://bitcoin.stackexchange.com/questions/102597/invalid-p2sh-transaction-accepted-by-the-network">fixed</a> my initial transactions and have been able to send coins to a p2sh address</p>
<p>Now I want to spend those coins but when I try to broadcast my transactions either the website (blockcypher) accept it and it is then later not accepted by miners or rejected (blockstream) with:</p>
<blockquote>
<p>sendrawtransaction RPC error:
{&quot;code&quot;:-26,&quot;message&quot;:&quot;non-mandatory-script-verify-flag (Extra items
left on stack after execution)&quot;}</p>
</blockquote>
<p>I think I have made the the correct ScriptSig for the 2 of 2 multisig (OP_0, sig1, sig2, redeemscript) so I am not sure of my error:</p>
<blockquote>
<p>OP_0 3045022100e91708339615eb38326a5c513b5dcc040bf59a1b97faef2c1f59a7b16426519a02200a4ca9d8c9f05ec824c70d1564ae2952650bc0ddc8bce92f081dd7d29d33d7ea01 3045022100ca0e751242a6d33ab2e895a9b1d9e5dce18426f2d11e69009e794ebc1004ba1a0220022a95a3f335fd84b380d6482948c24817a9f021f0dea75689eccf59e1540ae901 2d5214a175b609a7c37011420585f1fcf392fdda9a025414b1e9f0fa01914ff497607f99bf90dbd8a41bd8bb52ae</p>
</blockquote>
<p>And here is my full tx:</p>
<blockquote>
<p>0100000001f51f20dce174d1a894151bdbdf397317b97ec342c4068a6b96d95babb34baa7400000000c200483045022100e91708339615eb38326a5c513b5dcc040bf59a1b97faef2c1f59a7b16426519a02200a4ca9d8c9f05ec824c70d1564ae2952650bc0ddc8bce92f081dd7d29d33d7ea01483045022100ca0e751242a6d33ab2e895a9b1d9e5dce18426f2d11e69009e794ebc1004ba1a0220022a95a3f335fd84b380d6482948c24817a9f021f0dea75689eccf59e1540ae9012e2d5214a175b609a7c37011420585f1fcf392fdda9a025414b1e9f0fa01914ff497607f99bf90dbd8a41bd8bb52aeffffffff01401f0000000000001976a914a175b609a7c37011420585f1fcf392fdda9a025488ac00000000</p>
</blockquote>
<p>and the code I use to create it:</p>
<p><a href="https://pastebin.com/c0EvKjPH" rel="nofollow noreferrer">https://pastebin.com/c0EvKjPH</a></p>

CC BY-SA 4.0
2021-03-01T22:09:12.190Z
I think you might have prepended the length of the redeem script. The redeem script must start with "52" and not with "2d". Since this changes the tx, the signatures are no longer valid. Try signing the tx again without the "2d".
Oscar Serna
<transactions><script><development><multi-signature><p2sh>
Pay to script hash address transaction not accepted by miners
Saxtheowl
# Pay to script hash address transaction not accepted by miners

(Asked by: username_0 on 2021-03-01)

I have [fixed](https://bitcoin.stackexchange.com/questions/102597/invalid-p2sh-transaction-accepted-by-the-network) my initial transactions and have been able to send coins to a p2sh address

Now I want to spend those coins but when I try to broadcast my transactions either the website (blockcypher) accept it and it is then later not accepted by miners or rejected (blockstream) with:

> sendrawtransaction RPC error:
> {"code":-26,"message":"non-mandatory-script-verify-flag (Extra items
> left on stack after execution)"}

I think I have made the the correct ScriptSig for the 2 of 2 multisig (OP\_0, sig1, sig2, redeemscript) so I am not sure of my error:

> OP\_0 3045022100e91708339615eb38326a5c513b5dcc040bf59a1b97faef2c1f59a7b16426519a02200a4ca9d8c9f05ec824c70d1564ae2952650bc0ddc8bce92f081dd7d29d33d7ea01 3045022100ca0e751242a6d33ab2e895a9b1d9e5dce18426f2d11e69009e794ebc1004ba1a0220022a95a3f335fd84b380d6482948c24817a9f021f0dea75689eccf59e1540ae901 2d5214a175b609a7c37011420585f1fcf392fdda9a025414b1e9f0fa01914ff497607f99bf90dbd8a41bd8bb52ae

And here is my full tx:

> 0100000001f51f20dce174d1a894151bdbdf397317b97ec342c4068a6b96d95babb34baa7400000000c200483045022100e91708339615eb38326a5c513b5dcc040bf59a1b97faef2c1f59a7b16426519a02200a4ca9d8c9f05ec824c70d1564ae2952650bc0ddc8bce92f081dd7d29d33d7ea01483045022100ca0e751242a6d33ab2e895a9b1d9e5dce18426f2d11e69009e794ebc1004ba1a0220022a95a3f335fd84b380d6482948c24817a9f021f0dea75689eccf59e1540ae9012e2d5214a175b609a7c37011420585f1fcf392fdda9a025414b1e9f0fa01914ff497607f99bf90dbd8a41bd8bb52aeffffffff01401f0000000000001976a914a175b609a7c37011420585f1fcf392fdda9a025488ac00000000

and the code I use to create it:

<https://pastebin.com/c0EvKjPH>

**Tags:** transactions, script, development, multi-signature, p2sh

> **Comments:**
> **username_1**: I think you might have prepended the length of the redeem script. The redeem script must start with "52" and not with "2d". Since this changes the tx, the signatures are no longer valid. Try signing the tx again without the "2d".  

---

## 1 answers

### Answer by username_1 on 2021-03-01. Score: 1 | Accepted answer

Your redeem script has the length of the script prepended to it (`2d`), which causes the stack execution to finalize with the redeem script in the stack as data instead of interpreting it as another script.

The script interprets the `2d` as if you intended to put data in the stack with a length of 45 bytes, instead of actually interpreting your redeem script as a script. Therefore, Your redeem script must start with `52` and not the legth of the script which is 0x2d.

After you delete the `2d` from the redeem script, sign the tx again since this extra byte also changes the whole tx to sign.

Also, if you used that redeem script to compute your p2sh address, it is possible that you sent the money to the wrong address.

> **Comments:**
> **username_0**: It is funny while searching for help online I stumbled upon one of your question from here, Im gonna change my code then do the whole process again as you advise, luckily thats not real bitcoins  
> **username_1**: lol nice. Let me know how it goes.  

---

