1

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<string, object> prevTx = new Dictionary<string, object>() {
                    { "txid","3e4ea28160a9d5c9b01096ee17215e4bf6d3450ba97a963e3e8b8d969e04d303"} ,
                    { "scriptPubKey", "21033ff1181726af279fb2328e9ae041d71f323a91483f76841fe23aa03f87ecf3d3ac" },
                    { "vout", 0} };

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

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


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

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

        Dictionary<string, object> param = new Dictionary<string, object>()
                {
                    {"hexstring", TxRaw },
                    {"privkeys", new string[] { PrivateKey }},
                    {"prevtxs", new List<object>(){ 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();
    }

}
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"
        ]
      }
    }
  ]
}
  • 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 Feb 4 at 18:53
  • Are you using a library, where is SignTransactionAsync defined? – JBaczuk Feb 4 at 19:07
  • It's a helper method, just cover parameter passing and Http methods – Ali Harsini Feb 4 at 19:21
  • I am testing it with both depricated "signrawtransaction" and new one "signrawtransactionwithkey" but got the same error – Ali Harsini Feb 4 at 19:44
  • would need to see the function definitions – JBaczuk Feb 4 at 20:08
0

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<string, object> param = new Dictionary<string, object>()
            {
                {"hexstring", signedTx }
            };

    string decode = await disp.DecodeRawTransactionAsync(param);

The same should be done for sendrawtransaction.

  • 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 Feb 5 at 0:52
  • What does the resulting command string that is sent to bitcoind look like? – Andrew Chow Feb 5 at 1:31
  • "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 Feb 5 at 7:52
  • sorry, I can't formated comment to display correctly, and to fit into space I discard some text form "hexstring" and "privkeys" – Ali Harsini Feb 5 at 7:52
  • The problem is how you are passing privkeys here. You are giving an array of objects, but it is expecting an array of strings. – Andrew Chow Feb 5 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.