<p>I am using NBitcoin (I'm new to it) to sign a transaction. Here Transaction sign(secret, bool) method is giving error. (I've searched the Internet, but got no help.) Instead of bool it says to pass Coin object, I'm using the latest stable version of NBitcoin. How should I do this? Here's my code:</p>
<pre><code>var fee = Money.Coins(0.0001m);

        Transaction payment=Transaction.Create(bitcoinNetwork);
        payment.Inputs.Add(new TxIn()
        {
            PrevOut = new OutPoint(fundingTransaction.GetHash(), 1)
        });

        payment.Outputs.Add(new TxOut()
        {
            Value = amount-fee,
            ScriptPubKey = toAddress.ScriptPubKey
        });

        var output = fundingTransaction.Outputs[0];
       

        payment.Outputs.Add(new TxOut()
        {
            Value = output.Value - amount - fee,
            ScriptPubKey = output.ScriptPubKey
        });

        var message = &quot;Thanks :)&quot;;
        var bytes = Encoding.UTF8.GetBytes(message);
        payment.Outputs.Add(new TxOut()
        {
            Value = Money.Zero,
            ScriptPubKey = TxNullDataTemplate.Instance.GenerateScriptPubKey(bytes)
        });

        Console.WriteLine(payment);

        payment.Inputs[0].ScriptSig = fundingTransaction.Outputs[1].ScriptPubKey;

        payment.Sign(secret, false); // the problem arises here

        using (var node = Node.Connect(Network.Main))
        {
            Console.WriteLine(&quot;Doing version handshake&quot;);
            node.VersionHandshake();
            Console.WriteLine(&quot;Sending message&quot;);
            node.SendMessage(new InvPayload(InventoryType.MSG_TX, payment.GetHash()));
            node.SendMessage(new TxPayload(payment));
            Thread.Sleep(500);
        }
</code></pre>

<transactions><blockchain><client><c#><nbitcoin>
NBitcoin Transaction sign(secret, bool) is giving error. Instead of bool it says to pass Coin Object
Abhishek Pandey
# NBitcoin Transaction sign(secret, bool) is giving error. Instead of bool it says to pass Coin Object

(Asked by: username_0 on 2020-10-19)

I am using NBitcoin (I'm new to it) to sign a transaction. Here Transaction sign(secret, bool) method is giving error. (I've searched the Internet, but got no help.) Instead of bool it says to pass Coin object, I'm using the latest stable version of NBitcoin. How should I do this? Here's my code:
var fee = Money.Coins(0.0001m);

        Transaction payment=Transaction.Create(bitcoinNetwork);
        payment.Inputs.Add(new TxIn()
        {
            PrevOut = new OutPoint(fundingTransaction.GetHash(), 1)
        });

        payment.Outputs.Add(new TxOut()
        {
            Value = amount-fee,
            ScriptPubKey = toAddress.ScriptPubKey
        });

        var output = fundingTransaction.Outputs[0];
       

        payment.Outputs.Add(new TxOut()
        {
            Value = output.Value - amount - fee,
            ScriptPubKey = output.ScriptPubKey
        });

        var message = "Thanks :)";
        var bytes = Encoding.UTF8.GetBytes(message);
        payment.Outputs.Add(new TxOut()
        {
            Value = Money.Zero,
            ScriptPubKey = TxNullDataTemplate.Instance.GenerateScriptPubKey(bytes)
        });

        Console.WriteLine(payment);

        payment.Inputs[0].ScriptSig = fundingTransaction.Outputs[1].ScriptPubKey;

        payment.Sign(secret, false); // the problem arises here

        using (var node = Node.Connect(Network.Main))
        {
            Console.WriteLine("Doing version handshake");
            node.VersionHandshake();
            Console.WriteLine("Sending message");
            node.SendMessage(new InvPayload(InventoryType.MSG_TX, payment.GetHash()));
            node.SendMessage(new TxPayload(payment));
            Thread.Sleep(500);
        }

**Tags:** transactions, blockchain, client, c#, nbitcoin


---

## 0 answers

