You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I create a P2WSH (SegWit) multisig transaction that includes multiple signatures? I found examples for signing SegWit transactions but none of them are multisig. This particular one is for 2/3 multisig wallet and I need to create & sign a transaction using 2 of the private keys. I created the redeem script with txscript.MultiSigScript, calculated the p2wsh (bech32) address and sent funds to it. But I couldn't create & sign a transaction.
redeemTx:=wire.NewMsgTx(wire.TxVersion)
wifStr1:="..."//private keywif1, err:=btcutil.DecodeWIF(wifStr1)
iferr!=nil {
log.Fatal(err)
}
wifStr2:="..."//private keywif2, err:=btcutil.DecodeWIF(wifStr2)
iferr!=nil {
log.Fatal(err)
}
utxoHash, err:=chainhash.NewHashFromStr("UTXO hash...")
iferr!=nil {
log.Fatal(err)
}
// Index of the UTXO in the previous transaction.outPoint:=wire.NewOutPoint(utxoHash, 0)
txIn:=wire.NewTxIn(outPoint, nil, nil) // Create an input with empty signature script (for SegWit).redeemTx.AddTxIn(txIn)
decodedAddr, err:=btcutil.DecodeAddress("bc1...", &chaincfg.MainNetParams)
iferr!=nil {
log.Fatal(err)
}
destinationAddrByte, err:=txscript.PayToAddrScript(decodedAddr)
iferr!=nil {
log.Fatal(err)
}
redeemTxOut:=wire.NewTxOut(9000, destinationAddrByte)
redeemTx.AddTxOut(redeemTxOut)
// Ensure the scriptSig is empty (required for SegWit transactions).redeemTx.TxIn[0].SignatureScript=nilprevOutputFetcher:=txscript.NewMultiPrevOutFetcher(nil)
prevOutputFetcher.AddPrevOut(*outPoint, &wire.TxOut{
Value: 100000, // The value of the UTXO being spentPkScript: redeemScript,
})
sigHashes:=txscript.NewTxSigHashes(redeemTx, prevOutputFetcher)
sig1, err:=txscript.WitnessSignature(redeemTx, sigHashes, 0, 100000, redeemScript, txscript.SigHashAll, wif1.PrivKey, true)
iferr!=nil {
log.Fatal(err)
}
sig2, err:=txscript.WitnessSignature(redeemTx, sigHashes, 0, 100000, redeemScript, txscript.SigHashAll, wif2.PrivKey, true)
iferr!=nil {
log.Fatal(err)
}
redeemTx.TxIn[0].Witness= wire.TxWitness{} //what next? what to do for multiple signatures?// I also tried this code below but I get the error "Witness program hash mismatch" when broadcasting:sig1, err:=txscript.RawTxInSignature(redeemTx, sigHashes, 0, 100000, redeemScript, txscript.SigHashAll, wif1.PrivKey)
iferr!=nil {
log.Fatal(err)
}
sig2, err:=txscript.RawTxInSignature(redeemTx, sigHashes, 0, 100000, redeemScript, txscript.SigHashAll, wif2.PrivKey)
iferr!=nil {
log.Fatal(err)
}
redeemTx.TxIn[0].Witness= wire.TxWitness{sig1, sig2}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello.
How can I create a P2WSH (SegWit) multisig transaction that includes multiple signatures? I found examples for signing SegWit transactions but none of them are multisig. This particular one is for 2/3 multisig wallet and I need to create & sign a transaction using 2 of the private keys. I created the redeem script with txscript.MultiSigScript, calculated the p2wsh (bech32) address and sent funds to it. But I couldn't create & sign a transaction.
Beta Was this translation helpful? Give feedback.
All reactions