I'm attempting to use the Ledger Wallet API to sign a multi-sig transaction. The API works as follows:

var inputs = [
  [ "71f97fa2a21486ecd99674a8ae068d92acd2e9db49c199473be39984e6cbe0f6", "00000000" ],
  [ "171e6a969ff196a2cfaaba4780c292e33fc297672a065cc5c5c684727cf9e3ba", "00000001" ]

var scripts = [     

var paths = [

var outputs_number = 2
var outputs_script = "40420f00000000001976a91496986c2703c6b311c884bf916d28621bc61e8b7a88acdc0c03000000000017a914ddf0a9f3e0c9822feef702d36dee6c0bd2bf7c6d87"

Ledger.signP2SH(inputs, scripts, outputs_number, outputs_script, paths);

I have everything working except generating the outputs_script - I know there are ways to construct this manually, but I have to assume there's a mechanism within one of the javascript libraries out there. I found in the bitcoin.js library a method which will turn an address into an output script:

var outScript = bitcoin.address.toOutputScript("1LRVwrvGF6XxQbCzqEBG71cPv9RrF8Uu5P")

But that doesn't incorporate value or multiple addresses. How can I generate just the output script component, for a primary and change address, from a Javascript library?

1 Answer 1


I wrote a tiny module to do just this: https://github.com/lukechilds/build-output-script

It can be used like so:

const buildOutputScript = require('build-output-script');

buildOutputScript([{address: '1LukeQU5jwebXbMLDVydeH4vFSobRV9rkj', value: 100000000}]);
// '0100e1f505000000001976a914da6473ed373e08f46dd8003fca7ba72fbe9c555e88ac'

You can pass in multiple P2PKH addresses.

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.