Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
var alice = new SafeAccount(id: 2);
                var aliceAddress = safe.GetAddress(index: 1, hdPathType: HdPathType.Receive, account: alice);
                var alicePrivate = safe.FindPrivateKey(aliceAddress, account: alice); // safe.GetPrivateKey(index: 1, hdPathType: HdPathType.Receive, account: alice);

                var david = new SafeAccount(id: 3);
                var davidAddress = safe.GetAddress(index: 1, hdPathType: HdPathType.Receive, account: david);
                var davidPrivate = safe.FindPrivateKey(davidAddress, account: david); 
             
                Script redeemScript =
                    PayToMultiSigTemplate.Instance.GenerateScriptPubKey(
                        2,
                        alicePrivate.PrivateKey.PubKey, davidPrivate.PrivateKey.PubKey);

                var received = new Transaction();
                received.Outputs.Add(new TxOut(Money.Coins(0.0021m), redeemScript.WitHash.ScriptPubKey.Hash.ScriptPubKey));

                ScriptCoin bobAliceScriptCoin = received.Outputs.AsCoins().First().ToScriptCoin(redeemScript);

                var builder2 = new TransactionBuilder();
                var tx2 = builder2
                        .AddCoins(bobAliceScriptCoin)
                        .AddKeys(alicePrivate, davidPrivate)
                        .Send(addressToSend, Money.Coins(0.002m))
                        .SetChange(aliceAddress)
                        .SendFees(Money.Coins(0.0001m))
                        .BuildTransaction(true);
                Console.WriteLine(builder2.Verify(tx2));


What I have tried:

I would like to sign a P2SH(P2WSH) transaction but failed. Anyone can help to review the below codes?
Posted
Updated 26-Jun-18 18:08pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900