private void btnSignPrivkey_Click(object sender, EventArgs e) { PrivateKeyDialog pkd = new PrivateKeyDialog(); DialogResult res = pkd.ShowDialog(); if (res == DialogResult.Cancel) { return; } List <PrivateKey> keys = new List <PrivateKey>(); if (pkd.rbWIF.Checked) { foreach (TextBox tb in pkd.txtKeyList) { keys.Add(PrivateKey.FromWIF(tb.Text)); } } else if (pkd.rbHEX.Checked) { foreach (TextBox tb in pkd.txtKeyList) { keys.Add(PrivateKey.FromHex(tb.Text)); } } Transaction tx = new Transaction(HexString.ToByteArray(txtTx.Text)); for (int i = 0; i < tx.inputs.Length; i++) { foreach (PrivateKey pk in keys) { TxOut prevOut = selectedUTXO[new TxOutId(tx.inputs[i].prevOut, tx.inputs[i].prevOutIndex)]; Address a = Address.FromScript(prevOut.scriptPubKey); Address b; Script redeemScript = null; if (pkd.cbP2SH.Checked) { redeemScript = new Script(HexString.ToByteArray(pkd.txtRedeemScript.Text)); b = new Address(redeemScript.ToBytes(), Address.SCRIPT); } else { b = pk.pubKey.address; } if (a.ToString() == b.ToString()) { tx.inputs[i].Sign(tx, prevOut, pk, HashType.SIGHASH_ALL, redeemScript); } } } txtTx.Text = HexString.FromByteArray(tx.ToBytes()); }