I am trying to build a segwit transaction between a regular p2pkh address and a p2sh 2-of-2 multi-signature address. I have successfully transacted back and forth between these two addresses before (Testnet), but now I want to implement a segwit transaction. However, when I try to broadcast the transaction, it says "unexpected witness payload for non-witness script..". I am seeing the default witness field as "b'\x00'".

Documenting myself more about the subject, I found that "If all txins in a transaction are not associated with any witness data, the transaction MUST be serialized in the original transaction format, without marker, flag, and witness".

Does this mean that in order for me to test my segwit code, I will have to wait till I get a segwit input somehow?

This is my transaction hex:


Does this mean that in order for me to test my segwit code, I will have to wait till I get a segwit input somehow?

Yes. You have non-segwit inputs. You cannot create a segwit transaction when your transaction has only non-segwit inputs.

To get a segwit input, just send some of your Bitcoin to a segwit address that you own.


Only segwit outputs can be spent using segwit inputs.

A segwit transaction is a transaction with at least one segwit input.

You'll first need to create a segwit output to test segwit spending.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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