<p>Ahh, just found the answer. Should have read the help all the way through. It says: </p>

<blockquote>
  <p>The second optional argument (may be null) is an array of previous transaction outputs that
  this transaction depends on but may not yet be in the block chain.</p>
</blockquote>

<p>So, it's there so that the method can be used even if the transaction it depends on doesn't exist yet. If it does exist, however, the client is smart and does extra error checking to make sure that you don't mess up.</p>

CC BY-SA 3.0
2014-10-27T04:42:14.707Z
2014-10-27T04:42:14.707Z
morsecoder
<p>The <code>signrawtransaction</code> rpc method calls for the following use:</p>

<pre><code>signrawtransaction "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] ["privatekey1",...] sighashtype )
</code></pre>

<p>Why is scriptPubKey included in here? It seems from the code that it just looks it up anyway and compared to the value given:</p>

<pre>
if (coins.IsAvailable(nOut) && coins.vout[nOut].scriptPubKey != scriptPubKey) {
    string err("Previous output scriptPubKey mismatch:\n");
    err = err + coins.vout[nOut].scriptPubKey.ToString() + "\nvs:\n"+
    scriptPubKey.ToString();
    throw JSONRPCError(RPC_DESERIALIZATION_ERROR, err);
}
</pre>

<p>My best guesses:</p>

<ul>
<li>Maybe there are some cases where it won't be able to look up the scriptPubKey? </li>
<li>Maybe so this will work offline? </li>
<li>Maybe it's not actually needed, but kept for backwards compatibility?</li>
</ul>

<json-rpc><script>
Why is the scriptPubKey required when using signrawtransaction?
morsecoder
# Why is the scriptPubKey required when using signrawtransaction?

(Asked by: username_0 on 2014-10-27)

The `signrawtransaction` rpc method calls for the following use:

```
signrawtransaction "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] ["privatekey1",...] sighashtype )

```

Why is scriptPubKey included in here? It seems from the code that it just looks it up anyway and compared to the value given:

```

if (coins.IsAvailable(nOut) && coins.vout[nOut].scriptPubKey != scriptPubKey) {
    string err("Previous output scriptPubKey mismatch:\n");
    err = err + coins.vout[nOut].scriptPubKey.ToString() + "\nvs:\n"+
    scriptPubKey.ToString();
    throw JSONRPCError(RPC_DESERIALIZATION_ERROR, err);
}

```

My best guesses:

* Maybe there are some cases where it won't be able to look up the scriptPubKey?
* Maybe so this will work offline?
* Maybe it's not actually needed, but kept for backwards compatibility?

**Tags:** json-rpc, script


---

## 1 answers

### Answer by username_0 on 2014-10-27. Score: 2 | Accepted answer

Ahh, just found the answer. Should have read the help all the way through. It says:

> The second optional argument (may be null) is an array of previous transaction outputs that
> this transaction depends on but may not yet be in the block chain.

So, it's there so that the method can be used even if the transaction it depends on doesn't exist yet. If it does exist, however, the client is smart and does extra error checking to make sure that you don't mess up.


---

