1

My Javascript/typescript project uses bitcore-lib. It uses Script.buildScriptHashOut to build custom P2SH outputs. How do I spend from this custom output?

0

I could not find anywhere on the web about it. I was hopeless until I noticed that I could, without modifying the library.

First choose a similar class in Bitcore-lib.

  • multisigscripthash (<== suggested) or publickeyhash for P2SH outputs
  • multisig or publickey for bare script outputs (don't use these, these are nonstandard)

Then copy it to a new file in your project such as this one**. Do not use typescript classes even if your project is of kind Typescript.

Then change require paths. Also require inherit from NPM. As in the boilerplates above, we need to inherit from Transaction.Input

A function such as "buildP2SHPushIn" in the example should produce the redeemscript. Remember, the last element of P2SH redeem scripts is a push of the P2SH script.

And finally use addInput instead of the higher-level function from to add inputs as shown here**


**The examples are for Bitcoin Cash, but they can be used the same way in Bitcoin. Do not copy from them, however!

2
  • If the examples are for bcash or similar forks of Bitcoin, I would be careful in using them for Bitcoin or use a different library considering incidents like reddit.com/r/bsv/comments/jq9jv3/… – Prayank Apr 27 at 15:56
  • Well, the boilerplates listed in "First choose a similar class in Bitcore." are for BTC so I hope my answer is more useful than it is dangerous. I wasn't aware of that incident – MCCCS Apr 27 at 16:03

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.