<p>I wrote a tiny module to do just this: <a href="https://github.com/lukechilds/build-output-script" rel="nofollow noreferrer">https://github.com/lukechilds/build-output-script</a></p>

<p>It can be used like so:</p>

<pre><code>const buildOutputScript = require('build-output-script');

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

<p>You can pass in multiple P2PKH addresses.</p>

CC BY-SA 4.0
2018-12-05T10:58:21.023Z
2018-12-05T10:58:21.023Z
Luke Childs
<p>I'm attempting to use the <a href="https://github.com/LedgerHQ/ledger-wallet-api" rel="nofollow noreferrer">Ledger Wallet API</a> to sign a multi-sig transaction. The API works as follows:</p>

<pre><code>var inputs = [
  [ "71f97fa2a21486ecd99674a8ae068d92acd2e9db49c199473be39984e6cbe0f6", "00000000" ],
  [ "171e6a969ff196a2cfaaba4780c292e33fc297672a065cc5c5c684727cf9e3ba", "00000001" ]
];

var scripts = [     
"52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae", 
"522102afe2165371442437b86089a17e8d1c26d127e3723b19f568e9c11e326946111521032d139518b16c112d5f1a52157f1468c0b7a570c41673debee8cd2e53eb084df12103b13fe78b0320ceb77795c87ed72069f12edf64169d15f8f9827f0bb4fdbe760f53ae"
];    

var paths = [
  "44'/0'/0'/0/0/0/1",
  "44'/0'/0'/0/0/0/2",
];

var outputs_number = 2
var outputs_script = "40420f00000000001976a91496986c2703c6b311c884bf916d28621bc61e8b7a88acdc0c03000000000017a914ddf0a9f3e0c9822feef702d36dee6c0bd2bf7c6d87"

Ledger.signP2SH(inputs, scripts, outputs_number, outputs_script, paths);
</code></pre>

<p>I have everything working except generating the outputs_script - I know there are ways to construct this <a href="https://klmoney.wordpress.com/bitcoin-dissecting-transactions-part-2-building-a-transaction-by-hand/" rel="nofollow noreferrer">manually</a>, 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: </p>

<pre><code>var outScript = bitcoin.address.toOutputScript("1LRVwrvGF6XxQbCzqEBG71cPv9RrF8Uu5P")
</code></pre>

<p>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?</p>

<transactions><ledger-hardware-wallet><javascript><output><bitcoinjs>
Generating Output Script from Bitcoin.js or other Javascript Library
patwhite
# Generating Output Script from Bitcoin.js or other Javascript Library

(Asked by: username_0 on 2018-07-24)

I'm attempting to use the [Ledger Wallet API](https://github.com/LedgerHQ/ledger-wallet-api) to sign a multi-sig transaction. The API works as follows:

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

var scripts = [     
"52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae", 
"522102afe2165371442437b86089a17e8d1c26d127e3723b19f568e9c11e326946111521032d139518b16c112d5f1a52157f1468c0b7a570c41673debee8cd2e53eb084df12103b13fe78b0320ceb77795c87ed72069f12edf64169d15f8f9827f0bb4fdbe760f53ae"
];    

var paths = [
  "44'/0'/0'/0/0/0/1",
  "44'/0'/0'/0/0/0/2",
];

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](https://klmoney.wordpress.com/bitcoin-dissecting-transactions-part-2-building-a-transaction-by-hand/), 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?

**Tags:** transactions, ledger-hardware-wallet, javascript, output, bitcoinjs


---

## 1 answers

### Answer by username_1 on 2018-12-05. Score: 1

I wrote a tiny module to do just this: <https://github.com/username_1/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.


---

