1

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:

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:

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.

1 Answer 1

1

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

1
  • Thank you! Cannot upvote because I don't have enough reputation though
    – Dani69654
    Commented Jun 14 at 8:12

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.