<p>Yes, your understanding is right. Unlocking P2WSH requires you to provide <code>witnessScript</code> of which hash exactly matches the script hash inside <code>scriptPubKey</code>(which is <code>witnessUtxoScript</code> of your post).</p>
<p>There's no way of getting <code>witnessScript</code> of P2WSH output(or transaction) from utxo, but for your specific case the only missing part is LOCK_TIME so you can find if you loop over all possible LOCK_TIME number(as far as I know from 0 ~ 2 ** 32 -1)</p>
<p>Additionally, if your timelock script is not used with any other script, it wouldn't be spendable anyway as it ends with <code>OP_DROP</code></p>

CC BY-SA 4.0
2024-06-14T08:12:11.207Z
Thank you! Cannot upvote because I don't have enough reputation though
Dani69654
CC BY-SA 4.0
2024-06-14T01:17:04.423Z
2024-06-14T01:17:04.423Z
Hyunhum Cho
<p>I have a question regarding the retrieval of transaction parameters, specifically <code>LOCK_TIME</code> and <code>witnessScript</code>, for a P2WSH transaction I created.
Below is the relevant code snippet for generating the locking script using a specific LOCK_TIME:</p>
<pre class="lang-js prettyprint-override"><code>const TEN_MINUTES = 10 * 60;
const LOCK_TIME = bip65.encode({ utc: Math.floor(Date.now() / 1000) + TEN_MINUTES });

const LOCKING_SCRIPT = script.compile([
    script.number.encode(LOCK_TIME),
    opcodes.OP_CHECKLOCKTIMEVERIFY,
    opcodes.OP_DROP,
]);
</code></pre>
<p>When I want to spend from the address generated with this script, I understand that I need to know the exact <code>witnessUtxo.script</code> and <code>witnessScript</code> I used to lock the funds.</p>
<p>For the unlocking part, here’s how I am adding the input in my PSBT:</p>
<pre class="lang-js prettyprint-override"><code>PSBT.addInput({
    hash: TX_HASH,
    index: 0,
    sequence: 0xffffffff - 1,
    witnessUtxo: {
     // script: P2WSH.output!,
     script: Buffer.from('0020a3a67b9adeba96fba9717446c3c4e61a26d867f7defa602593004a5daa87f2ea'), 
     value: VALUE,
     
    },
    //witnessScript: LOCKING_SCRIPT,
    witnessScript: Buffer.from('04a9806b66b175', 'hex'),
});
</code></pre>
<p>I noticed I can easily retrieve the <code>witnessUtxoScript</code> by checking the txId on my node. However, I am unable to locate the <code>witnessScript</code> anywhere. <strong>It seems the only way to recreate it is by knowing the exact LOCK_TIME that was previously set.</strong></p>
<p>Is my understanding correct? Moreover, is there any way to find either the LOCK_TIME or the witnessScript once a transaction has been mined?</p>
<p>Thank you for your help.</p>

<bitcoinjs><locktime>
OP_CHECKLOCKTIMEVERIFY locktime
Dani69654
# OP_CHECKLOCKTIMEVERIFY locktime

(Asked by: username_0 on 2024-06-14)

I have a question regarding the retrieval of transaction parameters, specifically `LOCK_TIME` and `witnessScript`, for a P2WSH transaction I created.
Below is the relevant code snippet for generating the locking script using a specific LOCK\_TIME:

```js
const TEN_MINUTES = 10 * 60;
const LOCK_TIME = bip65.encode({ utc: Math.floor(Date.now() / 1000) + TEN_MINUTES });

const LOCKING_SCRIPT = script.compile([
    script.number.encode(LOCK_TIME),
    opcodes.OP_CHECKLOCKTIMEVERIFY,
    opcodes.OP_DROP,
]);

```

When I want to spend from the address generated with this script, I understand that I need to know the exact `witnessUtxo.script` and `witnessScript` I used to lock the funds.

For the unlocking part, here’s how I am adding the input in my PSBT:

```js
PSBT.addInput({
    hash: TX_HASH,
    index: 0,
    sequence: 0xffffffff - 1,
    witnessUtxo: {
     // script: P2WSH.output!,
     script: Buffer.from('0020a3a67b9adeba96fba9717446c3c4e61a26d867f7defa602593004a5daa87f2ea'), 
     value: VALUE,
     
    },
    //witnessScript: LOCKING_SCRIPT,
    witnessScript: Buffer.from('04a9806b66b175', 'hex'),
});

```

I noticed I can easily retrieve the `witnessUtxoScript` by checking the txId on my node. However, I am unable to locate the `witnessScript` anywhere. **It seems the only way to recreate it is by knowing the exact LOCK\_TIME that was previously set.**

Is my understanding correct? Moreover, is there any way to find either the LOCK\_TIME or the witnessScript once a transaction has been mined?

Thank you for your help.

**Tags:** bitcoinjs, locktime


---

## 1 answers

### Answer by username_1 on 2024-06-14. Score: 1 | Accepted answer

Yes, your understanding is right. Unlocking P2WSH requires you to provide `witnessScript` of which hash exactly matches the script hash inside `scriptPubKey`(which is `witnessUtxoScript` of your post).

There's no way of getting `witnessScript` of P2WSH output(or transaction) from utxo, but for your specific case the only missing part is LOCK\_TIME so you can find if you loop over all possible LOCK\_TIME number(as far as I know from 0 ~ 2 \*\* 32 -1)

Additionally, if your timelock script is not used with any other script, it wouldn't be spendable anyway as it ends with `OP_DROP`

> **Comments:**
> **username_0**: Thank you! Cannot upvote because I don't have enough reputation though  

---

