<p>You cannot use Bitcoin Core to create your transaction because it does not know what to do with non-standard inputs. There is no need to use <code>signrawtransaction</code> because you are not signing anything. In order to make your transaction spendable, you will need to do it manually by inserting the scriptSig that you figured out yourself.</p>

CC BY-SA 4.0
2021-05-19T08:54:30.913Z
`signrawtransaction` is deprecated at bitcoin core 0.21
liorko
CC BY-SA 3.0
2018-04-24T17:29:10.787Z
2018-04-24T17:29:10.787Z
Ava Chow
<p>You do not need to sign transaction because your redeemScript <code>"OP_ADD 7 OP_EQUAL"</code> does not contain <code>OP_CHECKSIG*</code> operations</p>

<p>Just fill the scriptSig</p>

<p>0200000001ca55af6fe5bba933b81a4a91f540ea1c10933f33abbf88d9740121dc16b3895500000000<strong>06515603935787</strong>ffffffff01004775e80000000017a914b9f330d64c88295017c651d2117785f212cb59938700000000</p>

CC BY-SA 3.0
2018-03-21T06:12:29.737Z
that would work, but is that the preferred way of doing so, or differently asked, is there a way using bitcoin-cli to fill the scriptSig?
jagodacarlito
CC BY-SA 3.0
2018-04-24T17:30:30.820Z
Bitcoin Core can't sign arbitrary scripts. You need to fill in the data yourself.
Pieter Wuille
CC BY-SA 3.0
2018-03-21T06:02:10.680Z
2018-03-21T06:08:53.973Z
2018-03-21T06:08:53.973Z
amaclin
<p>That produces scary errors and says that it's not <code>complete</code>. This is all correct. You can see that the signature has been partially successfully because the hex has gotten longer. Though the transaction has been partially signed, it's not done because it needs more signatures.</p>

<blockquote>
  <p><code>M-of-N</code> vs <code>N-of-N</code>: Obviously, if you have an <code>n-of-n</code> signature (like the 2-of-2 multisignature), then everyone has to sign, but if you have a <code>m-of-n</code> multisignature where <code>m &lt; n</code>, then the signature will be complete when only some (<code>m</code>) of the signers have signed.</p>
</blockquote>

CC BY-SA 4.0
2018-07-06T09:54:59.770Z
2018-07-06T09:54:59.770Z
TM.
<p>I'm seeking help in redeeming a p2sh transaction using the standard tools from bitcoin core, e.g., bitcoin-cli or using directly the RPC commands via curl would also be fine.</p>

<h2>Creating the P2SH address</h2>

<p>locking funds in a p2sh address is not the problem I assume, e.g., I handled it that way:</p>

<h3>intput</h3>

<pre><code>bitcoin-cli -regtest decodescript "935787"
</code></pre>

<h3>output</h3>

<pre><code>{
  "asm": "OP_ADD 7 OP_EQUAL",
  "type": "nonstandard",
  "p2sh": "2N2Mn4F9tUVy9cRTzBQhQTiMpi2Kpwzkyn6"
}
</code></pre>

<p>in order to redeem that script I would need two numbers equaling 7 right, e.g., 
<code>1 6</code></p>

<h2>Locking some funding in a p2sh</h2>

<p>so let's spend some funds into the p2sh</p>

<h3>input</h3>

<pre><code>bitcoin-cli -regtest sendtoaddress 2N2Mn4F9tUVy9cRTzBQhQTiMpi2Kpwzkyn6 40
</code></pre>

<h3>output</h3>

<pre><code>5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca```
</code></pre>

<p>here is the raw transaction </p>

<h3>input</h3>

<pre><code>bitcoin-cli --regtest getrawtransaction 5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca
</code></pre>

<h3>output</h3>

<pre><code>0200000001cef241d611112f7f9c98a8e825eb801dad923767126bee7c9ec190950c06ba24000000004847304402202d25bc67043c3cc2ec5fbf6b0bfe7e49b0a5f29e3891f5da005f3350188bc79502202ca014de3b60ede7f3b3bf2080ed33a06c9cb39f588178907f48b09caa0b1bca01feffffff0200286bee0000000017a91463f665a76eef10e84662c82bec9aff641edf42ec8750bb9a3b0000000017a914c12b3404c4e13900c5bfefc886533d7eb59524228766000000
</code></pre>

<p>or decoded it is:</p>

<pre><code>{
  "txid": "5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca",
  "hash": "5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca",
  "version": 2,
  "size": 187,
  "vsize": 187,
  "locktime": 102,
  "vin": [
    {
      "txid": "24ba060c9590c19e7cee6b12673792ad1d80eb25e8a8989c7f2f1111d641f2ce",
      "vout": 0,
      "scriptSig": {
        "asm": "304402202d25bc67043c3cc2ec5fbf6b0bfe7e49b0a5f29e3891f5da005f3350188bc79502202ca014de3b60ede7f3b3bf2080ed33a06c9cb39f588178907f48b09caa0b1bca[ALL]",
        "hex": "47304402202d25bc67043c3cc2ec5fbf6b0bfe7e49b0a5f29e3891f5da005f3350188bc79502202ca014de3b60ede7f3b3bf2080ed33a06c9cb39f588178907f48b09caa0b1bca01"
      },
      "sequence": 4294967294
    }
  ],
  "vout": [
    {
      "value": 40.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 63f665a76eef10e84662c82bec9aff641edf42ec OP_EQUAL",
        "hex": "a91463f665a76eef10e84662c82bec9aff641edf42ec87",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2N2Mn4F9tUVy9cRTzBQhQTiMpi2Kpwzkyn6"
        ]
      }
    },
    {
      "value": 9.99996240,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_HASH160 c12b3404c4e13900c5bfefc886533d7eb5952422 OP_EQUAL",
        "hex": "a914c12b3404c4e13900c5bfefc886533d7eb595242287",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2NArcA7oJfBkH6ZWBfh2TaTQkvKYMoK9xhd"
        ]
      }
    }
  ]
}
</code></pre>

<h2>Creating a new UTXO spending from that p2sh transaction</h2>

<p>now I want to redeem that tx, so first create a raw transaction with the old tx as input</p>

<h3>input</h3>

<pre><code>bitcoin-cli -regtest createrawtransaction "[{\"txid\":\"5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca\",\"vout\":0}]" "{\"2NACSKxqUhLRHTwaSN3xaJpti6BEPyDFSUJ\":39}"
</code></pre>

<h3>output</h3>

<pre><code>0200000001ca55af6fe5bba933b81a4a91f540ea1c10933f33abbf88d9740121dc16b389550000000000ffffffff01004775e80000000017a914b9f330d64c88295017c651d2117785f212cb59938700000000
</code></pre>

<h2>Signing that UTXO to redeem it</h2>

<p>and I figure in the next step I assume I'd have to sign the transaction using the redeemScript, i.e., the redeemScript is:</p>

<p><code>515603935787</code> 
which is the hex form of:
<code>1 6 PUSH 935787</code></p>

<p>I tried to sign the tx using: </p>

<h3>input</h3>

<pre><code>bitcoin-cli -regtest signrawtransaction "0200000001ca55af6fe5bba933b81a4a91f540ea1c10933f33abbf88d9740121dc16b389550000000000ffffffff01004775e80000000017a914b9f330d64c88295017c651d2117785f212cb59938700000000" "[{\"txid\":\"5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca\",\"vout\":0,\"scriptPubKey\":\"a91463f665a76eef10e84662c82bec9aff641edf42ec87\",\"redeemscript\":\"515603935787\"}]"
</code></pre>

<p>Output</p>

<pre><code>{
  "hex": "0200000001ca55af6fe5bba933b81a4a91f540ea1c10933f33abbf88d9740121dc16b389550000000000ffffffff01004775e80000000017a914b9f330d64c88295017c651d2117785f212cb59938700000000",
  "complete": false,
  "errors": [
    {
      "txid": "5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca",
      "vout": 0,
      "witness": [
      ],
      "scriptSig": "",
      "sequence": 4294967295,
      "error": "Unable to sign input, invalid stack size (possibly missing key)"
    }
  ]
}
</code></pre>

<p>and that's where I don't know any further. 
I always get the error <code>Unable to sign input, invalid stack size (possibly missing key)</code> any idea what I am missing? </p>

<p>kind regards,
Jagoda</p>

<p>note: I already had a look at various links here on stackexchange/stackoverflow and the official developer wiki but couldn't find an easy to follow tutorial.
Tutorials I had a look at which might be useful for future references:</p>

<ul>
<li><a href="https://gist.githubusercontent.com/gavinandresen/3966071/raw/ca21870c190ba0e90c1a30673e790ef5acd207d2/TwoOfThree.sh" rel="noreferrer">2 out of 3 multi sig (outdated)</a> </li>
<li><a href="https://bitcoin.stackexchange.com/questions/66197/step-by-step-example-to-redeem-a-p2sh-output-required">p2sh step by step example</a></li>
<li><a href="https://bitcoin.stackexchange.com/questions/29955/how-to-sign-bitcoin-transaction-with-bitcoind-and-non-bitcoind-wallet-private">sign raw transaction</a></li>
</ul>

CC BY-SA 4.0
2018-11-27T20:36:22.200Z
i'm in the exact same boat as you (i ended up executing the same commands you did and getting the same result). how did you end up solving for it?
tipu
<bitcoin-core><bitcoin-cli><p2sh>
Bitcoin-tx sign/redeem p2sh transaction (Unable to sign input, invalid stack size (possibly missing key))
jagodacarlito
# Bitcoin-tx sign/redeem p2sh transaction (Unable to sign input, invalid stack size (possibly missing key))

(Asked by: username_0 on 2018-03-21)

I'm seeking help in redeeming a p2sh transaction using the standard tools from bitcoin core, e.g., bitcoin-cli or using directly the RPC commands via curl would also be fine.

## Creating the P2SH address

locking funds in a p2sh address is not the problem I assume, e.g., I handled it that way:

### intput

```
bitcoin-cli -regtest decodescript "935787"

```

### output

```
{
  "asm": "OP_ADD 7 OP_EQUAL",
  "type": "nonstandard",
  "p2sh": "2N2Mn4F9tUVy9cRTzBQhQTiMpi2Kpwzkyn6"
}

```

in order to redeem that script I would need two numbers equaling 7 right, e.g.,
`1 6`

## Locking some funding in a p2sh

so let's spend some funds into the p2sh

### input

```
bitcoin-cli -regtest sendtoaddress 2N2Mn4F9tUVy9cRTzBQhQTiMpi2Kpwzkyn6 40

```

### output

```
5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca```

```

here is the raw transaction

### input

```
bitcoin-cli --regtest getrawtransaction 5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca

```

### output

```
0200000001cef241d611112f7f9c98a8e825eb801dad923767126bee7c9ec190950c06ba24000000004847304402202d25bc67043c3cc2ec5fbf6b0bfe7e49b0a5f29e3891f5da005f3350188bc79502202ca014de3b60ede7f3b3bf2080ed33a06c9cb39f588178907f48b09caa0b1bca01feffffff0200286bee0000000017a91463f665a76eef10e84662c82bec9aff641edf42ec8750bb9a3b0000000017a914c12b3404c4e13900c5bfefc886533d7eb59524228766000000

```

or decoded it is:

```
{
  "txid": "5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca",
  "hash": "5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca",
  "version": 2,
  "size": 187,
  "vsize": 187,
  "locktime": 102,
  "vin": [
    {
      "txid": "24ba060c9590c19e7cee6b12673792ad1d80eb25e8a8989c7f2f1111d641f2ce",
      "vout": 0,
      "scriptSig": {
        "asm": "304402202d25bc67043c3cc2ec5fbf6b0bfe7e49b0a5f29e3891f5da005f3350188bc79502202ca014de3b60ede7f3b3bf2080ed33a06c9cb39f588178907f48b09caa0b1bca[ALL]",
        "hex": "47304402202d25bc67043c3cc2ec5fbf6b0bfe7e49b0a5f29e3891f5da005f3350188bc79502202ca014de3b60ede7f3b3bf2080ed33a06c9cb39f588178907f48b09caa0b1bca01"
      },
      "sequence": 4294967294
    }
  ],
  "vout": [
    {
      "value": 40.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 63f665a76eef10e84662c82bec9aff641edf42ec OP_EQUAL",
        "hex": "a91463f665a76eef10e84662c82bec9aff641edf42ec87",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2N2Mn4F9tUVy9cRTzBQhQTiMpi2Kpwzkyn6"
        ]
      }
    },
    {
      "value": 9.99996240,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_HASH160 c12b3404c4e13900c5bfefc886533d7eb5952422 OP_EQUAL",
        "hex": "a914c12b3404c4e13900c5bfefc886533d7eb595242287",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2NArcA7oJfBkH6ZWBfh2TaTQkvKYMoK9xhd"
        ]
      }
    }
  ]
}

```

## Creating a new UTXO spending from that p2sh transaction

now I want to redeem that tx, so first create a raw transaction with the old tx as input

### input

```
bitcoin-cli -regtest createrawtransaction "[{\"txid\":\"5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca\",\"vout\":0}]" "{\"2NACSKxqUhLRHTwaSN3xaJpti6BEPyDFSUJ\":39}"

```

### output

```
0200000001ca55af6fe5bba933b81a4a91f540ea1c10933f33abbf88d9740121dc16b389550000000000ffffffff01004775e80000000017a914b9f330d64c88295017c651d2117785f212cb59938700000000

```

## Signing that UTXO to redeem it

and I figure in the next step I assume I'd have to sign the transaction using the redeemScript, i.e., the redeemScript is:

`515603935787`
which is the hex form of:
`1 6 PUSH 935787`

I tried to sign the tx using:

### input

```
bitcoin-cli -regtest signrawtransaction "0200000001ca55af6fe5bba933b81a4a91f540ea1c10933f33abbf88d9740121dc16b389550000000000ffffffff01004775e80000000017a914b9f330d64c88295017c651d2117785f212cb59938700000000" "[{\"txid\":\"5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca\",\"vout\":0,\"scriptPubKey\":\"a91463f665a76eef10e84662c82bec9aff641edf42ec87\",\"redeemscript\":\"515603935787\"}]"

```

Output

```
{
  "hex": "0200000001ca55af6fe5bba933b81a4a91f540ea1c10933f33abbf88d9740121dc16b389550000000000ffffffff01004775e80000000017a914b9f330d64c88295017c651d2117785f212cb59938700000000",
  "complete": false,
  "errors": [
    {
      "txid": "5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca",
      "vout": 0,
      "witness": [
      ],
      "scriptSig": "",
      "sequence": 4294967295,
      "error": "Unable to sign input, invalid stack size (possibly missing key)"
    }
  ]
}

```

and that's where I don't know any further.
I always get the error `Unable to sign input, invalid stack size (possibly missing key)` any idea what I am missing?

kind regards,
Jagoda

note: I already had a look at various links here on stackexchange/stackoverflow and the official developer wiki but couldn't find an easy to follow tutorial.
Tutorials I had a look at which might be useful for future references:

* [2 out of 3 multi sig (outdated)](https://gist.githubusercontent.com/gavinandresen/3966071/raw/ca21870c190ba0e90c1a30673e790ef5acd207d2/TwoOfThree.sh)
* [p2sh step by step example](https://bitcoin.stackexchange.com/questions/66197/step-by-step-example-to-redeem-a-p2sh-output-required)
* [sign raw transaction](https://bitcoin.stackexchange.com/questions/29955/how-to-sign-bitcoin-transaction-with-bitcoind-and-non-bitcoind-wallet-private)

**Tags:** bitcoin-core, bitcoin-cli, p2sh

> **Comments:**
> **username_1**: i'm in the exact same boat as you (i ended up executing the same commands you did and getting the same result). how did you end up solving for it?  

---

## 3 answers

### Answer by username_2 on 2018-04-24. Score: 3

You cannot use Bitcoin Core to create your transaction because it does not know what to do with non-standard inputs. There is no need to use `signrawtransaction` because you are not signing anything. In order to make your transaction spendable, you will need to do it manually by inserting the scriptSig that you figured out yourself.

> **Comments:**
> **username_3**: `signrawtransaction` is deprecated at bitcoin core 0.21  

---

### Answer by username_4 on 2018-03-21. Score: 2

You do not need to sign transaction because your redeemScript `"OP_ADD 7 OP_EQUAL"` does not contain `OP_CHECKSIG*` operations

Just fill the scriptSig

0200000001ca55af6fe5bba933b81a4a91f540ea1c10933f33abbf88d9740121dc16b3895500000000**06515603935787**ffffffff01004775e80000000017a914b9f330d64c88295017c651d2117785f212cb59938700000000

> **Comments:**
> **username_0**: that would work, but is that the preferred way of doing so, or differently asked, is there a way using bitcoin-cli to fill the scriptSig?  
> **username_5**: Bitcoin Core can't sign arbitrary scripts. You need to fill in the data yourself.  

---

### Answer by username_6 on 2018-07-06. Score: 0

That produces scary errors and says that it's not `complete`. This is all correct. You can see that the signature has been partially successfully because the hex has gotten longer. Though the transaction has been partially signed, it's not done because it needs more signatures.

> `M-of-N` vs `N-of-N`: Obviously, if you have an `n-of-n` signature (like the 2-of-2 multisignature), then everyone has to sign, but if you have a `m-of-n` multisignature where `m < n`, then the signature will be complete when only some (`m`) of the signers have signed.


---

