0

I have try to build a 2 of 2 p2sh transaction from scratch using the book "programming bitcoin" by Jimmy Song, we are not directly guided to make one of those so I had to modify some of the function we had to build in the book but I guess it must be working.

Here is my tx on testnet: https://www.blockchain.com/btc-testnet/tx/7eba40f4c00e3da529309011c6fd8066c97fd24adca60b0d024976c360bcdd8b

And here is my code: https://pastebin.com/1mCv73i2

using the functions of the book: https://github.com/jimmysong/programmingbitcoin

My question are:

  • Why did the transaction was accepted by the network despite not working as intended
  • Why did my input did not go to the desired p2sh address "2N7e6ZAGXoepdVYu2Y8ho7fTf6oxE3j9UwS"
  • It is on the testnet but if it was not can I retrieve my satoshis on this tx ?

edit: I found my error about my redeemscript and updated my code, but now I have a "Code: -25, Error: bad-txns-inputs-missingorspent" error when I want to broadcast it

here is my raw transaction, and I have updated the pastebin for the code: https://pastebin.com/8sQBpnVY

6
  • What do you believe to be invalid about the transaction? – Pieter Wuille Feb 13 at 23:40
  • Well, I just realize that I dont use the address I want to send the coin to anywhere, so I must have missed something, in fact im not sure as to where to put the address that will have a p2sh tx – Saxtheowl Feb 13 at 23:47
  • What do you mean with "P2SH tx"? Outputs can be P2SH or not, and a transaction can have a mix of P2SH and non-P2SH outputs. Inputs can be spending P2SH outputs or other outputs. Transactions can have a mix P2SH-output spending inputs and non-P2SH-output-spending inputs. It's not a property of the transaction, but of the individual inputs and outputs. – Pieter Wuille Feb 14 at 0:00
  • My error came from the fact that I use " 0x52, public_key1, public_key2, 0x52, 0xae " as my ScriptPubKey – Saxtheowl Feb 14 at 13:50
  • That's a valid multisig script. It doesn't have a corresponding address, but that doesn't make it invalid. – Pieter Wuille Feb 14 at 18:22
4

Why did the transaction was accepted by the network despite not working as intended

The network does not check the validity of output scripts. An output script can contain pretty much any data and the transaction will still be consensus valid. But your transaction is not actually invalid. It's just like a bare multisig now, but since the pubkeys are hashes, it isn't.

Why did my input did not go to the desired p2sh address "2N7e6ZAGXoepdVYu2Y8ho7fTf6oxE3j9UwS"

You set the output script to dat_redeem_script_op rather than target_script. So the output script is actually your multisig script rather than the P2SH script you intended.

It is on the testnet but if it was not can I retrieve my satoshis on this tx ?

No. Even if you had done this correctly with P2SH, it would still be unspendable. This is because your "public keys" are actually public key hashes. However you do not use any opcodes to for public key hashing. OP_CHECKMULTISIG takes public keys so it will try to interpret your public key hashes as pubkeys and fail to do so.

If you had constructed the multisig script correctly with public keys, this would be spendable as a bare multisig. It would be spendable in the same way that a P2SH multisig is spendable except you do not provide the multisig script in the input's scriptSig.

1
  • I could have delete the target_script line sorry, I mean if I use it instead of dat_redeem_script_op it will no longer be a p2sh transaction – Saxtheowl Feb 13 at 23:11

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.