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.

  • Could you share the raw transaction bytes (in hex) that you broadcasted? Commented Jun 24, 2021 at 8:58
  • Of course, this is what I'm broadcasting: 0100000000010179ebc0d716496a2803828657074196c073bf9be23a43604530deec6a7f6ef6660100000000ffffffff011c250000000000002200204a7642228c2f5688884cff5221714abaf58c9a5e32cf03549f7a75888acb10060247304402203fb1c7b9d5c93716968ef7e010923f123b816a6ff255ff401b3dbf090c69f430022044509913f254e107d32696cd930c6ff6a4968fc84ed7417cb80f100c9562bcc5012321029bed8c78bc0f557742303db2fb3c48e8b5025cf11cdf1cdea764805f234a443cac00000000 I'm broadcasting using: explorer.bc-2.jp/tx/push
    – katsu
    Commented Jun 24, 2021 at 9:00
  • Your signature is invalid. When OP_CheckSig is executed it pushes false to the stack that is probably why you get that error message. Commented Jun 24, 2021 at 9:18
  • 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
    Commented Jun 24, 2021 at 10:09

1 Answer 1


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 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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