<p>You are passing the parameter with <code>signedTx</code> incorrectly. A JSON-RPC <code>param</code> key must have a value that is either an array or an object. You are passing in a string. Instead you should pass in the parameter similarly to how you did for the <code>signrawtransactionwithkey</code> call.</p>

<p>You should have something like this:</p>

<pre><code>     Dictionary&lt;string, object&gt; param = new Dictionary&lt;string, object&gt;()
            {
                {"hexstring", signedTx }
            };

    string decode = await disp.DecodeRawTransactionAsync(param);
</code></pre>

<p>The same should be done for <code>sendrawtransaction</code>.</p>

CC BY-SA 4.0
2019-02-05T00:52:28.850Z
With passing command as array or collection then 
    it  says it wants a string type parameter
    {
    "result":null,
    "error":{ "code":-3,"message":"Expected type 
    string, got object"},
    "id":null
    }
Ali Harsini
CC BY-SA 4.0
2019-02-05T01:31:35.517Z
What does the resulting command string that is sent to bitcoind look like?
Ava Chow
CC BY-SA 4.0
2019-02-05T07:52:02.843Z
"method":"signrawtransactionwithkey",  
    "params":  
    {
    "hexstring":"0200000001810211089221fb6f6e0d0a4d5805f938f",
    "privkeys": ["{\"result\":\"cR4zAfhBqYb5zopnzbSPapHGMHzA\",\"error\":null,\"id\":null}\n"],
    "prevtxs":
        [{
        "txid":"20715ec617522f2530530828c8ab09fd38f905584d0a0d6e6ffb219208110281",
        "scriptPubKey":"210346335c729cda01ae00f29ebf9e3b31431ef4f6eb89a50fb4846ce3f4dd2a714dac",
        "vout":0,
        "amount":50.0
        }],
    "sighashtype":"ALL"
    }
Ali Harsini
CC BY-SA 4.0
2019-02-05T07:52:26.853Z
sorry, I can't formated comment to display correctly, and to fit into space I discard some text form "hexstring" and "privkeys"
Ali Harsini
CC BY-SA 4.0
2019-02-05T15:32:21.887Z
The problem is how you are passing privkeys here. You are giving an array of objects, but it is expecting an array of strings.
Ava Chow
CC BY-SA 4.0
2019-02-04T20:58:07.820Z
2019-02-04T20:58:07.820Z
Ava Chow
<p>Seems to be able to be decoded:</p>

<pre><code>$ bitcoin-cli -regtest decoderawtransaction 020000000103d3049e968d8b3e3e967aa90b45d3f64b5e2117ee9610b0c9d5a96081a24e3e000000004847304402201921a1acf601acb0f9e6297a55eeb853c2dd6cd246ea05f060eaa4d327d4124a02206e08e2c90b92113a64d6de1447f81bf19703f88bffeacc6d2cc4bf0e21ed8ac501ffffffff0200e1f5050000000017a9140796253e13d88cda530bf88b07eb1672952a3a7887608a0e24010000001976a914957b73da3bf34440ab2f78937a7a420835255a0988ac00000000
{
  "txid": "9cbedd5f9674aff9fff890cec60aa38dba074fcc3984c5a2b760ff69d2c9ea3f",
  "hash": "9cbedd5f9674aff9fff890cec60aa38dba074fcc3984c5a2b760ff69d2c9ea3f",
  "version": 2,
  "size": 189,
  "vsize": 189,
  "weight": 756,
  "locktime": 0,
  "vin": [
    {
      "txid": "3e4ea28160a9d5c9b01096ee17215e4bf6d3450ba97a963e3e8b8d969e04d303",
      "vout": 0,
      "scriptSig": {
        "asm": "304402201921a1acf601acb0f9e6297a55eeb853c2dd6cd246ea05f060eaa4d327d4124a02206e08e2c90b92113a64d6de1447f81bf19703f88bffeacc6d2cc4bf0e21ed8ac5[ALL]",
        "hex": "47304402201921a1acf601acb0f9e6297a55eeb853c2dd6cd246ea05f060eaa4d327d4124a02206e08e2c90b92113a64d6de1447f81bf19703f88bffeacc6d2cc4bf0e21ed8ac501"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 1.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 0796253e13d88cda530bf88b07eb1672952a3a78 OP_EQUAL",
        "hex": "a9140796253e13d88cda530bf88b07eb1672952a3a7887",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2MswLavAixrNJY2eN58LLT6xjwLqouwvASn"
        ]
      }
    },
    {
      "value": 48.99900000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 957b73da3bf34440ab2f78937a7a420835255a09 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914957b73da3bf34440ab2f78937a7a420835255a0988ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "mu9LsGdG3KFnpgB3Vx8w1sg8uCLb4gn3Uk"
        ]
      }
    }
  ]
}
</code></pre>

CC BY-SA 4.0
2019-02-04T18:53:39.467Z
yes you'r right, it's works fine with bitcoin-cli, but return error when called through the RPC in code. i am a little bit confused to where to looking for cause of error
Ali Harsini
CC BY-SA 4.0
2019-02-04T19:07:23.930Z
Are you using a library, where is `SignTransactionAsync` defined?
JBaczuk
CC BY-SA 4.0
2019-02-04T19:21:16.493Z
It's a helper method, just cover parameter passing and Http methods
Ali Harsini
CC BY-SA 4.0
2019-02-04T19:44:09.503Z
I am testing it with both depricated "signrawtransaction" and new one "signrawtransactionwithkey" but got the same error
Ali Harsini
CC BY-SA 4.0
2019-02-04T20:08:51.580Z
would need to see the function definitions
JBaczuk
CC BY-SA 4.0
2019-02-04T20:11:58.473Z
public async Task<string> SignTransactionWithKeyAsync(Dictionary<string, object> param)
    {
    RPCCommand cmd = new RPCCommand()
    {
    Method = "signrawtransactionwithkey",
    Params = param,
    Id = 0
    };
         
    string cmdRequest = server.SerializeCommand(cmd, true);
         
    string jsonStr = await server.PostCommand(cmdRequest, server.serverAddress);
         
    return jsonStr;
    }
Ali Harsini
CC BY-SA 4.0
2019-02-04T20:34:52.033Z
I don't know what `RPCCommand()` does
JBaczuk
CC BY-SA 4.0
2019-02-04T18:39:47.473Z
2019-02-04T18:39:47.473Z
JBaczuk
<p>I am able to sign following transaction with Complete=true result, but when trying to decode signed transaction, it returns error "TX decode failed" both from DecodeRawTransaction and SendRawTransaction RPC calls.</p>

<pre><code>signed_Tx = "020000000103d3049e968d8b3e3e967aa90b45d3f64b5e2117ee9610b0c9d5a96081a24e3e000000004847304402201921a1acf601acb0f9e6297a55eeb853c2dd6cd246ea05f060eaa4d327d4124a02206e08e2c90b92113a64d6de1447f81bf19703f88bffeacc6d2cc4bf0e21ed8ac501ffffffff0200e1f5050000000017a9140796253e13d88cda530bf88b07eb1672952a3a7887608a0e24010000001976a914957b73da3bf34440ab2f78937a7a420835255a0988ac00000000"

[TestMethod()]
public async Task CreateRawTxTest()
{
    Dictionary&lt;string, object&gt; prevTx = new Dictionary&lt;string, object&gt;() {
                    { "txid","3e4ea28160a9d5c9b01096ee17215e4bf6d3450ba97a963e3e8b8d969e04d303"} ,
                    { "scriptPubKey", "21033ff1181726af279fb2328e9ae041d71f323a91483f76841fe23aa03f87ecf3d3ac" },
                    { "vout", 0} };

    List&lt;object&gt; txIn = new List&lt;object&gt;()
            {
                new Dictionary&lt;string, object&gt;() {
                    { "txid","3e4ea28160a9d5c9b01096ee17215e4bf6d3450ba97a963e3e8b8d969e04d303"},
                    { "vout", 0} }
            };

    List&lt;object&gt; txOut = new List&lt;object&gt;()
            {
                new Dictionary&lt;string, float&gt;
                {
                    { TestNet_ReceiverAddress, 1.0f}
                },
                new Dictionary&lt;string, float&gt;
                {
                    { "TestNet_SenderAddress", 48.99900f }
                },
            };


    RPCResultPrime&lt;string&gt; rawResult = await disp.CreateRawTransactionAsync(txIn, txOut);

    if (rawResult.Error == null)
    {
        string TxRaw = rawResult.Result;

        Dictionary&lt;string, object&gt; param = new Dictionary&lt;string, object&gt;()
                {
                    {"hexstring", TxRaw },
                    {"privkeys", new string[] { PrivateKey }},
                    {"prevtxs", new List&lt;object&gt;(){ prevTx } }
                    {"sighashtype", "ALL" }
                };

        string signedTx = await disp.SignTransactionAsync(param);

        //at this point transaction signed successfully but could not be Decoded in the next step

        string decode = await disp.DecodeRawTransactionAsync(signedTx);

        string jsonSend = await disp.SendRawTransactionAsync(signedTx);

        Debugger.Break();
    }

}
</code></pre>

<transactions><signrawtransaction>
Could not sign Transaction with SignRawTransactionWithKey through the RPC (RegTest)
Ali Harsini
# Could not sign Transaction with SignRawTransactionWithKey through the RPC (RegTest)

(Asked by: username_0 on 2019-02-04)

I am able to sign following transaction with Complete=true result, but when trying to decode signed transaction, it returns error "TX decode failed" both from DecodeRawTransaction and SendRawTransaction RPC calls.
signed_Tx = "020000000103d3049e968d8b3e3e967aa90b45d3f64b5e2117ee9610b0c9d5a96081a24e3e000000004847304402201921a1acf601acb0f9e6297a55eeb853c2dd6cd246ea05f060eaa4d327d4124a02206e08e2c90b92113a64d6de1447f81bf19703f88bffeacc6d2cc4bf0e21ed8ac501ffffffff0200e1f5050000000017a9140796253e13d88cda530bf88b07eb1672952a3a7887608a0e24010000001976a914957b73da3bf34440ab2f78937a7a420835255a0988ac00000000"

[TestMethod()]
public async Task CreateRawTxTest()
{
    Dictionary prevTx = new Dictionary() {
                    { "txid","3e4ea28160a9d5c9b01096ee17215e4bf6d3450ba97a963e3e8b8d969e04d303"} ,
                    { "scriptPubKey", "21033ff1181726af279fb2328e9ae041d71f323a91483f76841fe23aa03f87ecf3d3ac" },
                    { "vout", 0} };

    List txIn = new List()
            {
                new Dictionary() {
                    { "txid","3e4ea28160a9d5c9b01096ee17215e4bf6d3450ba97a963e3e8b8d969e04d303"},
                    { "vout", 0} }
            };

    List txOut = new List()
            {
                new Dictionary
                {
                    { TestNet_ReceiverAddress, 1.0f}
                },
                new Dictionary
                {
                    { "TestNet_SenderAddress", 48.99900f }
                },
            };


    RPCResultPrime rawResult = await disp.CreateRawTransactionAsync(txIn, txOut);

    if (rawResult.Error == null)
    {
        string TxRaw = rawResult.Result;

        Dictionary param = new Dictionary()
                {
                    {"hexstring", TxRaw },
                    {"privkeys", new string[] { PrivateKey }},
                    {"prevtxs", new List(){ prevTx } }
                    {"sighashtype", "ALL" }
                };

        string signedTx = await disp.SignTransactionAsync(param);

        //at this point transaction signed successfully but could not be Decoded in the next step

        string decode = await disp.DecodeRawTransactionAsync(signedTx);

        string jsonSend = await disp.SendRawTransactionAsync(signedTx);

        Debugger.Break();
    }

}

**Tags:** transactions, signrawtransaction


---

## 2 answers

### Answer by username_1 on 2019-02-04. Score: 1

You are passing the parameter with signedTx incorrectly. A JSON-RPC param key must have a value that is either an array or an object. You are passing in a string. Instead you should pass in the parameter similarly to how you did for the signrawtransactionwithkey call.
You should have something like this:
     Dictionary param = new Dictionary()
            {
                {"hexstring", signedTx }
            };

    string decode = await disp.DecodeRawTransactionAsync(param);

The same should be done for sendrawtransaction.

> **Comments:**
> **username_0**: With passing command as array or collection then      it  says it wants a string type parameter     {     "result":null,     "error":{ "code":-3,"message":"Expected type      string, got object"},     "id":null     }  
> **username_1**: What does the resulting command string that is sent to bitcoind look like?  
> **username_0**: "method":"signrawtransactionwithkey",       "params":       {     "hexstring":"0200000001810211089221fb6f6e0d0a4d5805f938f",     "privkeys": ["{\"result\":\"cR4zAfhBqYb5zopnzbSPapHGMHzA\",\"error\":null,\"id\":null}\n"],     "prevtxs":         [{         "txid":"20715ec617522f2530530828c8ab09fd38f905584d0a0d6e6ffb219208110281",         "scriptPubKey":"210346335c729cda01ae00f29ebf9e3b31431ef4f6eb89a50fb4846ce3f4dd2a714dac",         "vout":0,         "amount":50.0         }],     "sighashtype":"ALL"     }  
> **username_0**: sorry, I can't formated comment to display correctly, and to fit into space I discard some text form "hexstring" and "privkeys"  
> **username_1**: The problem is how you are passing privkeys here. You are giving an array of objects, but it is expecting an array of strings.  

---

### Answer by username_2 on 2019-02-04. Score: 0

Seems to be able to be decoded:
$ bitcoin-cli -regtest decoderawtransaction 020000000103d3049e968d8b3e3e967aa90b45d3f64b5e2117ee9610b0c9d5a96081a24e3e000000004847304402201921a1acf601acb0f9e6297a55eeb853c2dd6cd246ea05f060eaa4d327d4124a02206e08e2c90b92113a64d6de1447f81bf19703f88bffeacc6d2cc4bf0e21ed8ac501ffffffff0200e1f5050000000017a9140796253e13d88cda530bf88b07eb1672952a3a7887608a0e24010000001976a914957b73da3bf34440ab2f78937a7a420835255a0988ac00000000
{
  "txid": "9cbedd5f9674aff9fff890cec60aa38dba074fcc3984c5a2b760ff69d2c9ea3f",
  "hash": "9cbedd5f9674aff9fff890cec60aa38dba074fcc3984c5a2b760ff69d2c9ea3f",
  "version": 2,
  "size": 189,
  "vsize": 189,
  "weight": 756,
  "locktime": 0,
  "vin": [
    {
      "txid": "3e4ea28160a9d5c9b01096ee17215e4bf6d3450ba97a963e3e8b8d969e04d303",
      "vout": 0,
      "scriptSig": {
        "asm": "304402201921a1acf601acb0f9e6297a55eeb853c2dd6cd246ea05f060eaa4d327d4124a02206e08e2c90b92113a64d6de1447f81bf19703f88bffeacc6d2cc4bf0e21ed8ac5[ALL]",
        "hex": "47304402201921a1acf601acb0f9e6297a55eeb853c2dd6cd246ea05f060eaa4d327d4124a02206e08e2c90b92113a64d6de1447f81bf19703f88bffeacc6d2cc4bf0e21ed8ac501"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 1.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 0796253e13d88cda530bf88b07eb1672952a3a78 OP_EQUAL",
        "hex": "a9140796253e13d88cda530bf88b07eb1672952a3a7887",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2MswLavAixrNJY2eN58LLT6xjwLqouwvASn"
        ]
      }
    },
    {
      "value": 48.99900000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 957b73da3bf34440ab2f78937a7a420835255a09 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914957b73da3bf34440ab2f78937a7a420835255a0988ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "mu9LsGdG3KFnpgB3Vx8w1sg8uCLb4gn3Uk"
        ]
      }
    }
  ]
}

> **Comments:**
> **username_0**: yes you'r right, it's works fine with bitcoin-cli, but return error when called through the RPC in code. i am a little bit confused to where to looking for cause of error  
> **username_2**: Are you using a library, where is `SignTransactionAsync` defined?  
> **username_0**: It's a helper method, just cover parameter passing and Http methods  
> **username_0**: I am testing it with both depricated "signrawtransaction" and new one "signrawtransactionwithkey" but got the same error  
> **username_2**: would need to see the function definitions  
> **username_0**: public async Task<string> SignTransactionWithKeyAsync(Dictionary<string, object> param)     {     RPCCommand cmd = new RPCCommand()     {     Method = "signrawtransactionwithkey",     Params = param,     Id = 0     };               string cmdRequest = server.SerializeCommand(cmd, true);               string jsonStr = await server.PostCommand(cmdRequest, server.serverAddress);               return jsonStr;     }  
> **username_2**: I don't know what `RPCCommand()` does  

---

