signrawtransactionwithwallet 显示错误无法签署输入,无效堆栈大小(可能缺少密钥)

Posted

技术标签:

【中文标题】signrawtransactionwithwallet 显示错误无法签署输入,无效堆栈大小(可能缺少密钥)【英文标题】:signrawtransactionwithwallet shows error Unable to sign input, invalid stack size (possibly missing key) 【发布时间】:2020-11-06 14:25:13 【问题描述】:

我正在尝试在比特币测试网中发送交易。 所以我这样做:创建输入和输出数组,然后调用 createrawtransaction 并获取事务十六进制。然后我打电话给decoderawtransaction 看到这个:

stdClass Object
(
    [txid] => b7374ebb31a77eb65cc146bfca8d09ac84e7ced068e121fedee90d6205a8481a
    [hash] => b7374ebb31a77eb65cc146bfca8d09ac84e7ced068e121fedee90d6205a8481a
    [version] => 2
    [size] => 158
    [vsize] => 158
    [weight] => 632
    [locktime] => 0
    [vin] => Array
        (
            [0] => stdClass Object
                (
                    [txid] => 8d3c81d39d9d852b347490934b78f22137454706ea96c5cb61c1d1336d3c0440
                    [vout] => 0
                    [scriptSig] => stdClass Object
                        (
                            [asm] =>
                            [hex] =>
                        )

                    [sequence] => 4294967295
                )

            [1] => stdClass Object
                (
                    [txid] => abd5a3c9abf946d90730b37f2f0dd2eab48cf1520bdccf2174a57c49991b5f81
                    [vout] => 0
                    [scriptSig] => stdClass Object
                        (
                            [asm] =>
                            [hex] =>
                        )

                    [sequence] => 4294967295
                )

        )

    [vout] => Array
        (
            [0] => stdClass Object
                (
                    [value] => 0.00091799
                    [n] => 0
                    [scriptPubKey] => stdClass Object
                        (
                            [asm] => OP_HASH160 626e89f8d256f31e3f18787e50fc2b874251e004 OP_EQUAL
                            [hex] => a914626e89f8d256f31e3f18787e50fc2b874251e00487
                            [reqSigs] => 1
                            [type] => scripthash
                            [addresses] => Array
                                (
                                    [0] => 2N2DgdTtbrfBg65c1DrnuzJnAvSWWr4gkNS
                                )

                        )

                )

            [1] => stdClass Object
                (
                    [value] => 0.01509785
                    [n] => 1
                    [scriptPubKey] => stdClass Object
                        (
                            [asm] => OP_DUP OP_HASH160 6f4d68c699514a84cf4588bca6b8c7314b90b8c0 OP_EQUALVERIFY OP_CHECKSIG
                            [hex] => 76a9146f4d68c699514a84cf4588bca6b8c7314b90b8c088ac
                            [reqSigs] => 1
                            [type] => pubkeyhash
                            [addresses] => Array
                                (
                                    [0] => mqfU2qaG2BtrEqnovAbcRExvzHByvm1rPB
                                )

                        )

                )

        )

)

但是当我在这个事务的十六进制上调用 signrawtransactionwithwallet 时,我得到了错误:

stdClass Object
(
    [result] => stdClass Object
        (
            [hex] => 020000000240043c6d33d1c161cbc596ea0647453721f2784b939074342b859d9dd3813c8d0000000000ffffffff815f1b99497ca57421cfdc0b52f18cb4ead20d2f7fb33007d946f9abc9a3d5ab0000000000ffffffff02976601000000000017a914626e89f8d256f31e3f18787e50fc2b874251e0048799091700000000001976a9146f4d68c699514a84cf4588bca6b8c7314b90b8c088ac00000000
            [complete] =>
            [errors] => Array
                (
                    [0] => stdClass Object
                        (
                            [txid] => 8d3c81d39d9d852b347490934b78f22137454706ea96c5cb61c1d1336d3c0440
                            [vout] => 0
                            [witness] => Array
                                (
                                )

                            [scriptSig] =>
                            [sequence] => 4294967295
                            [error] => Unable to sign input, invalid stack size (possibly missing key)
                        )

                    [1] => stdClass Object
                        (
                            [txid] => abd5a3c9abf946d90730b37f2f0dd2eab48cf1520bdccf2174a57c49991b5f81
                            [vout] => 0
                            [witness] => Array
                                (
                                )

                            [scriptSig] =>
                            [sequence] => 4294967295
                            [error] => Unable to sign input, invalid stack size (possibly missing key)
                        )

                )

        )

    [error] =>
    [id] =>
)

哪里有问题?好像和教程https://medium.com/@piyushpruthi/sending-raw-transactions-in-bitcoin-dacef2269d1b一样,只是bitoin api略有变化……

【问题讨论】:

【参考方案1】:

是的,在本教程中,signrawtransaction 已被弃用。

    你有发件人的私钥吗? getaddressinfo / dumpprivkey

    你加载钱包了吗? loadwallet

或者,您可以转储您的私钥并签署交易。 signrawtransactionwithkey

【讨论】:

getaddressinfo 显示这个:对于发件人地址(只有一个发件人地址):```“地址”:“2N2DgdTtbrfBg65c1DrnuzJnAvSWWr4gkNS”,“scriptPubKey”:“a914626e89f8d256f31e3f18787e50fc2b87 ,“可解”:假,“iswatchonly”:真,“isscript”:真,“iswitness”:假,“标签”:“eobmen”,“ischange”:假,“时间戳”:1,“标签”:[ "name": "eobmen", " purpose": "receive" ] ``` and dumpprivkey show error Address does not refer to a key 也许问题是这个地址是为了接收而创建的? 是的。好像你没有发件人地址的私钥【参考方案2】:

解决了。问题是,发件人地址没有对应的私钥(我不知道它是怎么发生的)

【讨论】:

以上是关于signrawtransactionwithwallet 显示错误无法签署输入,无效堆栈大小(可能缺少密钥)的主要内容,如果未能解决你的问题,请参考以下文章