Search code examples
transactionsbitcoin

Signrawtransactionwithkey is returning "Unable to sign input, invalid stack size (possibly missing key)"


Node is Bitcoin Core 24.0. I'm trying to sign a raw transaction with private key that is not imported in the wallet.

Raw transaction hex: 0200000001d882ccfb5b012fc7f0ff80f88ad455397364b05924aa757eae6bc5ad686f02040100000000fdffffff0180841e00000000001976a9147270eaf36eb7849c81a1d21a8f4d15d81d03f54c88ac00000000

Decoded transaction:

bitcoin-cli decoderawtransaction "0200000001d882ccfb5b012fc7f0ff80f88ad455397364b05924aa757eae6bc5ad686f02040100000000fdffffff0180841e00000000001976a9147270eaf36eb7849c81a1d21a8f4d15d81d03f54c88ac00000000"
{
  "txid": "b9a6f80ecc13920db5d47e7a08cc50a271827c689fc95ef9b86721533d274de0",
  "hash": "b9a6f80ecc13920db5d47e7a08cc50a271827c689fc95ef9b86721533d274de0",
  "version": 2,
  "size": 85,
  "vsize": 85,
  "weight": 340,
  "locktime": 0,
  "vin": [
    {
      "txid": "04026f68adc56bae7e75aa2459b064733955d48af880fff0c72f015bfbcc82d8",
      "vout": 1,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967293
    }
  ],
  "vout": [
    {
      "value": 0.02000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 7270eaf36eb7849c81a1d21a8f4d15d81d03f54c OP_EQUALVERIFY OP_CHECKSIG",
        "desc": "addr(mqx4bb2C4gZehqDoPKVZifkGXTdGghbPSZ)#a49n9ch9",
        "hex": "76a9147270eaf36eb7849c81a1d21a8f4d15d81d03f54c88ac",
        "address": "mqx4bb2C4gZehqDoPKVZifkGXTdGghbPSZ",
        "type": "pubkeyhash"
      }
    }
  ]
}

Signrawtransactionwithkey output:

bitcoin-cli signrawtransactionwithkey "0200000001d882ccfb5b012fc7f0ff80f88ad455397364b05924aa757eae6bc5ad686f02040100000000fdffffff0180841e00000000001976a9147270eaf36eb7849c81a1d21a8f4d15d81d03f54c88ac00000000" "[\"<privkey>\"]"

{
  "hex": "0200000001d882ccfb5b012fc7f0ff80f88ad455397364b05924aa757eae6bc5ad686f02040100000000fdffffff0180841e00000000001976a9147270eaf36eb7849c81a1d21a8f4d15d81d03f54c88ac00000000",
  "complete": false,
  "errors": [
    {
      "txid": "04026f68adc56bae7e75aa2459b064733955d48af880fff0c72f015bfbcc82d8",
      "vout": 1,
      "witness": [
      ],
      "scriptSig": "",
      "sequence": 4294967293,
      "error": "Unable to sign input, invalid stack size (possibly missing key)"
    }
  ]
}
  • Is it possible to sign transactions without importing the key (that I sign with)?
  • What is the proper way to do it? (if not)

Tried different privkeys, txids to generate rawtransaction hex


Solution

  • Most likely, problem cause was either:

    • I was creating raw transaction in the wrong way.
    • Commission was too low.

    Although, both causes have different error messages. I can't reproduce the issue as of now.

    Syntax that works (1 utxo, 1 recipient):

    bitcoin-cli createrawtransaction '[{
                "txid" : "04026f68adc56bae7e75aa2459b064733955d48af880fff0c72f015bfbcc82d8",
                "vout" : 1
            }]' '{
          "n1cDpTFBVV3s7P1Bt7wKZrAjQpZBuGt2ya": 0.04893500
        }'
    

    Syntax that didn't work - 1 utxo, 1 recipient, 1 change recipient (same as utxo holder)

    bitcoin-cli createrawtransaction
        '[{
            "txid" : "04026f68adc56bae7e75aa2459b064733955d48af880fff0c72f015bfbcc82d8",
            "vout" : 1
        }]'
        '{"n1cDpTFBVV3s7P1Bt7wKZrAjQpZBuGt2ya": 0.03, 
        "mqx4bb2C4gZehqDoPKVZifkGXTdGghbPSZ": 0.01}'
    
    

    Summing up, you actually can sign transaction with key that is not imported using "signrawtransactionwithkey" on Core v24.0.