<p>Here is the reference for creating a P2SH multisig address <a href="https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L44" rel="nofollow noreferrer">https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L44</a></p>
<p>However your question states &quot;custom&quot; P2SH so I think you might be asking about something more advanced, in which case I would suggest reviewing <code>bitcoin.script.compile</code>, the CLTV address for example:</p>
<pre class="lang-js prettyprint-override"><code>    let bitcoin = require(&quot;bitcoinjs-lib&quot;);
    let bip65 = require('bip65');
    
    function cltvCheckSigOutput (aQ, bQ, lockTime) {
        return bitcoin.script.compile([
          bitcoin.opcodes.OP_IF,
          bitcoin.script.number.encode(lockTime),
          bitcoin.opcodes.OP_CHECKLOCKTIMEVERIFY,
          bitcoin.opcodes.OP_DROP,
    
          bitcoin.opcodes.OP_ELSE,
          bQ.publicKey,
          bitcoin.opcodes.OP_CHECKSIGVERIFY,
          bitcoin.opcodes.OP_ENDIF,
    
          aQ.publicKey,
          bitcoin.opcodes.OP_CHECKSIG
        ])
      }     
    
      function utcNow () {
        return Math.floor(Date.now() / 1000)
      }

    let NETWORK = bitcoin.networks.testnet;  
    let alice = bitcoin.ECPair.fromWIF('cScfkGjbzzoeewVWmU2hYPUHeVGJRDdFt7WhmrVVGkxpmPP8BHWe', NETWORK); 
    let bob = bitcoin.ECPair.fromWIF('cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsLwjHXA9x', NETWORK)
    
    //set lock time for 3 hours from now
    let lockTime = bip65.encode({ utc: utcNow() + (3600 * 3) });

    let redeemScript = cltvCheckSigOutput(alice, bob, lockTime);
    let scriptPubKey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript));
    let address = bitcoin.address.fromOutputScript(scriptPubKey, NETWORK);

    console.log(address);
</code></pre>

CC BY-SA 4.0
2018-06-19T15:36:50.797Z
Thanks. I am actually looking for a JS script in `bitcoinjs-lib` or `bitcore-lib` to create NON MULTISIG, so a normal P2SH address from a `redeemScript`. Or even from a `customString` for that matter.
Robert
CC BY-SA 4.0
2018-06-19T16:02:52.327Z
To be clear, in this article it mentions about a "special bitcoin address which are essentially Base58Check encodings of the 20 byte hash of the redeem script.". How are these "special addresses" created? But not the multisig ones, just an address which is the hash of a redeemScript.  https://medium.com/@ismailakkila/my-notes-on-bitcoin-transactions-part-2-c9d39d5ae326. @m1xolyd1an
Robert
CC BY-SA 4.0
2018-06-19T16:15:30.590Z
Maybe this is what what I am looking for. https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L25
Robert
CC BY-SA 4.0
2018-06-20T04:09:34.393Z
Essentially it is just `bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript));` where `redeemScript` is equal to an OP code script array `bitcoin.script.compile([bitcoin.opcodes.OP_IF,  bitcoin.script.number.encode(lockTime),...])`
m1xolyd1an
CC BY-SA 4.0
2018-06-19T05:05:41.440Z
2024-02-26T13:48:36.183Z
2024-02-26T13:48:36.183Z
m1xolyd1an
<p>I was looking to create custom P2SH addresses from <code>redeemScripts</code> ( they start with 3...) using <code>bictore-lib</code>.</p>

<p>If anyone can direct me to the right code in their module, I can't find it. </p>

<bitcore>
How to create a P2SH address with bitcore-lib
Robert
# How to create a P2SH address with bitcore-lib

(Asked by: username_0 on 2018-06-18)

I was looking to create custom P2SH addresses from `redeemScripts` ( they start with 3...) using `bictore-lib`.

If anyone can direct me to the right code in their module, I can't find it.

**Tags:** bitcore


---

## 1 answers

### Answer by username_1 on 2018-06-19. Score: 2 | Accepted answer

Here is the reference for creating a P2SH multisig address <https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L44>

However your question states "custom" P2SH so I think you might be asking about something more advanced, in which case I would suggest reviewing `bitcoin.script.compile`, the CLTV address for example:

```js
    let bitcoin = require("bitcoinjs-lib");
    let bip65 = require('bip65');
    
    function cltvCheckSigOutput (aQ, bQ, lockTime) {
        return bitcoin.script.compile([
          bitcoin.opcodes.OP_IF,
          bitcoin.script.number.encode(lockTime),
          bitcoin.opcodes.OP_CHECKLOCKTIMEVERIFY,
          bitcoin.opcodes.OP_DROP,
    
          bitcoin.opcodes.OP_ELSE,
          bQ.publicKey,
          bitcoin.opcodes.OP_CHECKSIGVERIFY,
          bitcoin.opcodes.OP_ENDIF,
    
          aQ.publicKey,
          bitcoin.opcodes.OP_CHECKSIG
        ])
      }     
    
      function utcNow () {
        return Math.floor(Date.now() / 1000)
      }

    let NETWORK = bitcoin.networks.testnet;  
    let alice = bitcoin.ECPair.fromWIF('cScfkGjbzzoeewVWmU2hYPUHeVGJRDdFt7WhmrVVGkxpmPP8BHWe', NETWORK); 
    let bob = bitcoin.ECPair.fromWIF('cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsLwjHXA9x', NETWORK)
    
    //set lock time for 3 hours from now
    let lockTime = bip65.encode({ utc: utcNow() + (3600 * 3) });

    let redeemScript = cltvCheckSigOutput(alice, bob, lockTime);
    let scriptPubKey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript));
    let address = bitcoin.address.fromOutputScript(scriptPubKey, NETWORK);

    console.log(address);

```

> **Comments:**
> **username_0**: Thanks. I am actually looking for a JS script in `bitcoinjs-lib` or `bitcore-lib` to create NON MULTISIG, so a normal P2SH address from a `redeemScript`. Or even from a `customString` for that matter.  
> **username_0**: To be clear, in this article it mentions about a "special bitcoin address which are essentially Base58Check encodings of the 20 byte hash of the redeem script.". How are these "special addresses" created? But not the multisig ones, just an address which is the hash of a redeemScript.  https://medium.com/@ismailakkila/my-notes-on-bitcoin-transactions-part-2-c9d39d5ae326. @username_1  
> **username_0**: Maybe this is what what I am looking for. https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L25  
> **username_1**: Essentially it is just `bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript));` where `redeemScript` is equal to an OP code script array `bitcoin.script.compile([bitcoin.opcodes.OP_IF,  bitcoin.script.number.encode(lockTime),...])`  

---

