<p>This was not a case of BitcoinLib malfunctioning in any way. It was simply a case of using wrong privkeys to sign the unspent outputs. </p>

CC BY-SA 3.0
2014-08-29T15:24:36.033Z
2014-08-29T15:24:36.033Z
angelitto
<p>I've been working with <a href="https://github.com/GeorgeKimionis/BitcoinLib" rel="nofollow noreferrer">BitcoinLib</a> testing various parameters on the signrawtransaction rpc call. </p>

<p>It's been mostly successful, however there seems to be a persisting problem when using only private keys to sign a transaction. (second optional argument of signrawtransaction call). The server replies <code>false</code> and returns the failed hex. I have tested the same transaction on the qt console using the same keys, and it returns <code>true</code>. </p>

<p>The wrapper employs a <code>SignRawTransactionRequest</code> class matching the four arguments of the rpc call.</p>

<pre><code>public SignRawTransactionRequest(String rawTransactionHex)
    {
        RawTransactionHex = rawTransactionHex;
        Inputs = new List&lt;SignRawTransactionInput&gt;();
        PrivateKeys = new List&lt;String&gt;();
        SigHashType = SignRawTransaction.SigHashType.All;
    }
</code></pre>

<p>It allows for 'inputs' and 'privatekeys' to be null, following the signrawtransaction syntax, while assuming 'sighashtype=all' unless explicitly specified otherwise.</p>

<p>The implementation also includes a <code>SignRawTransactionInput</code> class corresponding to the first optional argument of the rpc call. ([{"txid":txid,"vout":n, "scriptPubKey":hex, "redeemScript":hex } ,...])</p>

<pre><code>public class SignRawTransactionInput
{
    [JsonProperty(PropertyName = "txid", Order = 0)]
    public String TransactionId { get; set; }

    [JsonProperty(PropertyName = "vout", Order = 1)]
    public Int32 Output { get; set; }

    [JsonProperty(PropertyName = "scriptPubKey", Order = 2)]
    public String ScriptPubKey { get; set; }

    [JsonProperty(PropertyName = "redeemScript", Order = 3)]
    public String RedeemScript { get; set; }
}
</code></pre>

<p>The request if fed to the wrapper method <code>RpcServer.SignRawTransaction</code> and returns a <code>SignRawTransactionResponse</code> containing the result and the hex as returned by the server.</p>

<pre><code>public class SignRawTransactionResponse
    {
        public String Hex { get; set; }
        public Boolean Complete { get; set; }
    }
</code></pre>

<p>So far, signings using just the hex (no other arguments), inputs, different sighashtypes and various combinations of those have been successful. The server replies TRUE and returns the hex of the signed transaction when called with plain hex</p>

<p><img src="https://i.sstatic.net/LrgnQ.jpg" alt="enter image description here">
<img src="https://i.sstatic.net/Ie8H1.jpg" alt="server reply"></p>

<p>or when called with some arguments</p>

<p><img src="https://i.sstatic.net/0US3Q.jpg" alt="enter image description here"></p>

<p><img src="https://i.sstatic.net/SylqS.jpg" alt="enter image description here"></p>

<p>However, it returns false when the second optional argument(list of private keys) is used. It has been tested with one, all, and various combinations of the available private keys of the wallet. </p>

<p><img src="https://i.sstatic.net/ciq6u.jpg" alt="enter image description here"> <img src="https://i.sstatic.net/mg2FL.jpg" alt="enter image description here"></p>

<p>I suspect it might be a JSON error and that the wrapper is not constructing that part of the JSON properly, however that usually leads to a parsing error and not the <code>false</code> reply I get here.</p>

<p>The same combinations return <code>true</code> when signrawtransaction is called from the console.</p>

<p><img src="https://i.sstatic.net/n66v9.jpg" alt="enter image description here"></p>

<p>Any ideas on what might be wrong with the private keys argument?</p>

<json-rpc><private-key><c#>
JSON-RPC signrawtransaction returns false when using private keys
angelitto
# JSON-RPC signrawtransaction returns false when using private keys

(Asked by: username_0 on 2014-01-11)

I've been working with [BitcoinLib](https://github.com/GeorgeKimionis/BitcoinLib) testing various parameters on the signrawtransaction rpc call.

It's been mostly successful, however there seems to be a persisting problem when using only private keys to sign a transaction. (second optional argument of signrawtransaction call). The server replies `false` and returns the failed hex. I have tested the same transaction on the qt console using the same keys, and it returns `true`.

The wrapper employs a `SignRawTransactionRequest` class matching the four arguments of the rpc call.

```
public SignRawTransactionRequest(String rawTransactionHex)
    {
        RawTransactionHex = rawTransactionHex;
        Inputs = new List<SignRawTransactionInput>();
        PrivateKeys = new List<String>();
        SigHashType = SignRawTransaction.SigHashType.All;
    }

```

It allows for 'inputs' and 'privatekeys' to be null, following the signrawtransaction syntax, while assuming 'sighashtype=all' unless explicitly specified otherwise.

The implementation also includes a `SignRawTransactionInput` class corresponding to the first optional argument of the rpc call. ([{"txid":txid,"vout":n, "scriptPubKey":hex, "redeemScript":hex } ,...])

```
public class SignRawTransactionInput
{
    [JsonProperty(PropertyName = "txid", Order = 0)]
    public String TransactionId { get; set; }

    [JsonProperty(PropertyName = "vout", Order = 1)]
    public Int32 Output { get; set; }

    [JsonProperty(PropertyName = "scriptPubKey", Order = 2)]
    public String ScriptPubKey { get; set; }

    [JsonProperty(PropertyName = "redeemScript", Order = 3)]
    public String RedeemScript { get; set; }
}

```

The request if fed to the wrapper method `RpcServer.SignRawTransaction` and returns a `SignRawTransactionResponse` containing the result and the hex as returned by the server.

```
public class SignRawTransactionResponse
    {
        public String Hex { get; set; }
        public Boolean Complete { get; set; }
    }

```

So far, signings using just the hex (no other arguments), inputs, different sighashtypes and various combinations of those have been successful. The server replies TRUE and returns the hex of the signed transaction when called with plain hex

![enter image description here](https://i.sstatic.net/LrgnQ.jpg)
![server reply](https://i.sstatic.net/Ie8H1.jpg)

or when called with some arguments

![enter image description here](https://i.sstatic.net/0US3Q.jpg)

![enter image description here](https://i.sstatic.net/SylqS.jpg)

However, it returns false when the second optional argument(list of private keys) is used. It has been tested with one, all, and various combinations of the available private keys of the wallet.

![enter image description here](https://i.sstatic.net/ciq6u.jpg) ![enter image description here](https://i.sstatic.net/mg2FL.jpg)

I suspect it might be a JSON error and that the wrapper is not constructing that part of the JSON properly, however that usually leads to a parsing error and not the `false` reply I get here.

The same combinations return `true` when signrawtransaction is called from the console.

![enter image description here](https://i.sstatic.net/n66v9.jpg)

Any ideas on what might be wrong with the private keys argument?

**Tags:** json-rpc, private-key, c#


---

## 1 answers

### Answer by username_0 on 2014-08-29. Score: 1 | Accepted answer

This was not a case of BitcoinLib malfunctioning in any way. It was simply a case of using wrong privkeys to sign the unspent outputs.


---

