Tuesday, November 5, 2024

bitcoinjs – OP_CHECKLOCKTIMEVERIFY locktime – Bitcoin Stack Change

I’ve a query concerning the retrieval of transaction parameters, particularly LOCK_TIME and witnessScript, for a P2WSH transaction I created.
Beneath is the related code snippet for producing the locking script utilizing a selected LOCK_TIME:

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

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

Once I need to spend from the tackle generated with this script, I perceive that I have to know the precise witnessUtxo.script and witnessScript I used to lock the funds.

For the unlocking half, right here’s how I’m including the enter in my PSBT:

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

I observed I can simply retrieve the witnessUtxoScript by checking the txId on my node. Nonetheless, I’m unable to find the witnessScript anyplace. It appears the one approach to recreate it’s by realizing the precise LOCK_TIME that was beforehand set.

Is my understanding right? Furthermore, is there any approach to discover both the LOCK_TIME or the witnessScript as soon as a transaction has been mined?

Thanks in your assist.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles