Bitcoin

How to spend from a custom P2SH script using bitcore-lib

I couldn’t find anything about it anywhere on the web. I was desperate until I found out that I could do it without modifying the library.

First select a similar class from Bitcore-lib.

  • multisigscripthash (<== suggested) or publickeyhash for P2SH output
  • Multiple signatures or public keys for bare script output (don’t use these as they are non-standard)

Then copy it to a new file in your project, like this file**. Do not use Typescript classes, even if your project is of Typescript type.

then change require Route. Also required inherit In NPM. As in the boilerplate above, you need to inherit from: Transaction.Input

Functions like “buildP2SHPushIn” in the example should generate a redemption script. Remember that the last element of the P2SH exchange script is the P2SH script push.

And finally use addInput Instead of higher level features from To add input as shown here**


**The example is for Bitcoin Cash, but it can be used in the same way on Bitcoin. But don’t copy!

Related Articles

Back to top button