<p>Answering for anyone who might come across this. My linked script is invalid, I tried to spend funds from txout for which I don't have access for.</p>
<p>The <a href="https://github.com/petertodd/python-bitcoinlib/blob/master/examples/spend-p2wsh-txout.py" rel="nofollow noreferrer">linked script</a> works as expected and if you follow its steps it will work as expected. Please note that <code>python-bitcoinlib</code> does not have support for signet and I have made modifications to it locally.</p>

CC BY-SA 4.0
2021-11-28T16:09:16.433Z
2021-11-28T16:09:16.433Z
katsu
<p>I've tried to find an answer here and on BTT but without luck so far.</p>
<p>I'm having issues creating a transaction to spend from a <code>P2WSH</code> <a href="https://explorer.bc-2.jp/address/tb1qhxy36055wje22qkxn4mtjl4k9vykcnq7avgtu3smnw6xpdxmw0qqjvywtn" rel="nofollow noreferrer">address</a> which I created and sent funds to.</p>
<p>I based my code off of this example: <a href="https://github.com/petertodd/python-bitcoinlib/blob/master/examples/spend-p2wsh-txout.py" rel="nofollow noreferrer">https://github.com/petertodd/python-bitcoinlib/blob/master/examples/spend-p2wsh-txout.py</a></p>
<p>My code can be found here: <a href="https://gist.github.com/i0x0ff/b29b2307b4e9ce316a4d6533464cf7a1" rel="nofollow noreferrer">https://gist.github.com/i0x0ff/b29b2307b4e9ce316a4d6533464cf7a1</a></p>
<p>P2WSH <a href="https://explorer.bc-2.jp/address/tb1qhxy36055wje22qkxn4mtjl4k9vykcnq7avgtu3smnw6xpdxmw0qqjvywtn" rel="nofollow noreferrer">address with funds</a>: <code>tb1qhxy36055wje22qkxn4mtjl4k9vykcnq7avgtu3smnw6xpdxmw0qqjvywtn</code></p>
<p>I want to send funds to: <code>tb1qffmyyg5v9atg3zzvlafzzu22ht6cexj7xt8sx4yl0f6c3zktzqrq8hempj</code></p>
<p>When broadcasting the transaction I get the following error:</p>
<pre><code>{
  &quot;code&quot;: -26,
  &quot;message&quot;: &quot;non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation)&quot;,
}
</code></pre>
<p>One thing to note is that, I'm making this transaction on <strong>SIGNET</strong> and I've modified the code in the python-bitcoinlib to support SIGNET. I intend to make a PR for after I figure out this problem.</p>
<p>If there's any more information that I can provide in order to make it easier for anyone to help out, let me know what else would be useful. I'm just starting out with development on Bitcoin and will also document my process, finding and learnings.</p>

CC BY-SA 4.0
2021-06-24T08:58:04.727Z
Could you share the raw transaction bytes (in hex) that you broadcasted?
Coding Enthusiast
CC BY-SA 4.0
2021-06-24T09:00:35.853Z
Of course, this is what I'm broadcasting: 
`0100000000010179ebc0d716496a2803828657074196c073bf9be23a43604530deec6a7f6ef6660100000000ffffffff011c250000000000002200204a7642228c2f5688884cff5221714abaf58c9a5e32cf03549f7a75888acb10060247304402203fb1c7b9d5c93716968ef7e010923f123b816a6ff255ff401b3dbf090c69f430022044509913f254e107d32696cd930c6ff6a4968fc84ed7417cb80f100c9562bcc5012321029bed8c78bc0f557742303db2fb3c48e8b5025cf11cdf1cdea764805f234a443cac00000000`

I'm broadcasting using: https://explorer.bc-2.jp/tx/push
katsu
CC BY-SA 4.0
2021-06-24T09:18:49.210Z
Your signature is invalid. When `OP_CheckSig` is executed it pushes `false` to the stack that is probably why you get that error message.
Coding Enthusiast
CC BY-SA 4.0
2021-06-24T10:09:16.030Z
Thank you. I'm trying to read through the code and am comparing with my notes but can't figure out which steps I'm doing wrong that produce an invalid signature. Will keep on digging.
katsu
<python><p2wsh><python-bitcoinlib>
Problem spending funds from P2WSH address: non-mandatory-script-verify-flag
katsu
# Problem spending funds from P2WSH address: non-mandatory-script-verify-flag

(Asked by: username_0 on 2021-06-24)

I've tried to find an answer here and on BTT but without luck so far.
I'm having issues creating a transaction to spend from a P2WSH address which I created and sent funds to.
I based my code off of this example: https://github.com/petertodd/python-bitcoinlib/blob/master/examples/spend-p2wsh-txout.py
My code can be found here: https://gist.github.com/i0x0ff/b29b2307b4e9ce316a4d6533464cf7a1
P2WSH address with funds: tb1qhxy36055wje22qkxn4mtjl4k9vykcnq7avgtu3smnw6xpdxmw0qqjvywtn
I want to send funds to: tb1qffmyyg5v9atg3zzvlafzzu22ht6cexj7xt8sx4yl0f6c3zktzqrq8hempj
When broadcasting the transaction I get the following error:
{
  "code": -26,
  "message": "non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation)",
}

One thing to note is that, I'm making this transaction on SIGNET and I've modified the code in the python-bitcoinlib to support SIGNET. I intend to make a PR for after I figure out this problem.
If there's any more information that I can provide in order to make it easier for anyone to help out, let me know what else would be useful. I'm just starting out with development on Bitcoin and will also document my process, finding and learnings.

**Tags:** python, p2wsh, python-bitcoinlib

> **Comments:**
> **username_1**: Could you share the raw transaction bytes (in hex) that you broadcasted?  
> **username_0**: Of course, this is what I'm broadcasting:  `0100000000010179ebc0d716496a2803828657074196c073bf9be23a43604530deec6a7f6ef6660100000000ffffffff011c250000000000002200204a7642228c2f5688884cff5221714abaf58c9a5e32cf03549f7a75888acb10060247304402203fb1c7b9d5c93716968ef7e010923f123b816a6ff255ff401b3dbf090c69f430022044509913f254e107d32696cd930c6ff6a4968fc84ed7417cb80f100c9562bcc5012321029bed8c78bc0f557742303db2fb3c48e8b5025cf11cdf1cdea764805f234a443cac00000000`  I'm broadcasting using: https://explorer.bc-2.jp/tx/push  
> **username_1**: Your signature is invalid. When `OP_CheckSig` is executed it pushes `false` to the stack that is probably why you get that error message.  
> **username_0**: Thank you. I'm trying to read through the code and am comparing with my notes but can't figure out which steps I'm doing wrong that produce an invalid signature. Will keep on digging.  

---

## 1 answers

### Answer by username_0 on 2021-11-28. Score: 0 | Accepted answer

Answering for anyone who might come across this. My linked script is invalid, I tried to spend funds from txout for which I don't have access for.

The [linked script](https://github.com/petertodd/python-bitcoinlib/blob/master/examples/spend-p2wsh-txout.py) works as expected and if you follow its steps it will work as expected. Please note that `python-bitcoinlib` does not have support for signet and I have made modifications to it locally.


---

