Closed educob closed 1 year ago
I have no idea what the script is, but if the witnessScript contains either your DER pubkey or the HASH160 hash of the pubkey for keyPair
, this should work.
// address creation
const script = this.generateBitcoinScript(tree, signers)
const redeemScript = bitcoin.script.compile(script)
const p2wsh = bitcoin.payments.p2wsh({ redeem: { output: redeemScript, network }, network )
// REMOVE const p2sh = bitcoin.payments.p2sh({ redeem: p2wsh, network})
const address = p2wsh.address
// spend bitcoins
const script = p2wsh.output
// REMOVE const redeemScript = p2sh.redeem.output
const witnessScript = p2wsh.redeem.output
// ... create psbt, addOputs.
psbt.addInput({ hash, index,
// REMOVE redeemScript,
witnessScript,
witnessUtxo: {
script,
value,
}}
)
psbt.signInput(i, keyPair)
Thanks for answering.
When broadcasting the transaction I get error:
RpcError: non-mandatory-script-verify-flag (Witness requires empty scriptSig) (code 64)
My regtest bitcoind node is 0.18. Could It be that?
Regards.
Can you show the complete code?
You are probably doing something else that is placing data in the scriptSig (P2WSH will never touch the scriptSig unless it's inside a P2SH)
Hi Jonathan.
Thanks to pasting you the whole code I realized that the code that was dealing with the script execution path was still using p2sh.
Now it works.
Thanks a lot for your help.
Hi.
At the moment I am using P2sh to generate the address and to spend it.
This is the code:
How do I use just P2WSH (not using P2SH)?
With multisignature it has been as easy as removing redeemScript from addInput.
Thanks.