<p>These are API names and display scripts in their encoded and or decoded form. What you want to build a transaction is the encoded form like the one returned by toshi (script_hex) or smartbit (hex).</p>

<p>A script is a sequence of instructions beginning by OP_ (OP_DUP, etc...) and hex data. You can read more about the Script language <a href="https://en.bitcoin.it/wiki/Script" rel="nofollow">here</a>.</p>

<p>At the protocol level, all of the instructions and data are concatenated to form a single (encoded) hex blob of the script: </p>

<pre><code>76a914cba5f746dc1e41a932a7d38be7aba95944619ee888ac
</code></pre>

<p>This is what is signed by the transaction builder. However, it's not really intelligible for us humans. That's why these APIs decode the hex into the sequence of instructions they encode:</p>

<pre><code>OP_DUP (0x76)
OP_HASH160 (0xa9)
(0x14 means 20 bytes of data are next)
cba5f746dc1e41a932a7d38be7aba95944619ee8
OP_EQUALVERIFY (0x88)
OP_CHECKSIG (0xac)
</code></pre>

<p>The traditional way of showing this decoded script is :</p>

<pre><code>OP_DUP OP_HASH160 cba5f746dc1e41a932a7d38be7aba95944619ee8 OP_EQUALVERIFY OP_CHECKSIG
</code></pre>

CC BY-SA 3.0
2016-10-01T20:48:34.620Z
So with webbtc `"scriptPubKey"` (this is protocol level script data!), Must I **encrypt** or **sign** the data with my private key in order to create the hex blob of the script?
Ben Muircroft
CC BY-SA 3.0
2016-10-01T21:30:57.557Z
Not you directly, that's the role of Bitpay's transaction builder. As long as you provide it the keys locking the outputs, it'll do all the signing needed to make the transaction valid.
alcio
CC BY-SA 3.0
2016-10-01T19:51:41.400Z
2016-10-01T22:36:28.580Z
2016-10-01T22:36:28.580Z
alcio
<p>I am really confused and I am having trouble even asking this question in a coherent manner (as I am trying to describe things that other people have renamed multiple times in different instances) so please bear with me...</p>

<p>I am trying to build a transaction using each api I find so I am normalizing the structure of the response from each api call into </p>

<p>Bitcores expected format for the unspent outputs:</p>

<pre><code>[
    {
      "address": "2Mwswt6Eih28xH8611fexpqKqJCLJMomveK",
      "scriptPubKey": "a91432d272ce8a9b482b363408a0b1dd28123d59c63387",
      "txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
      "vout": 1,
      "amount": 1.0,
      "confirmations":7
    }
    , { ... }
]
</code></pre>

<h2>from: <a href="https://blog.bitpay.com/transactionbuilder/" rel="nofollow">https://blog.bitpay.com/transactionbuilder/</a></h2>

<p>But different apis are returning different parts of data</p>

<p>webbtc.com/address api unspent has only scriptPubKey</p>

<pre><code>"scriptPubKey": "OP_DUP OP_HASH160 cba5f746dc1e41a932a7d38be7aba95944619ee8 OP_EQUALVERIFY OP_CHECKSIG"
</code></pre>

<p>whereas toshi.io api unspent has</p>

<pre><code>"script":"OP_DUP OP_HASH160 cba5f746dc1e41a932a7d38be7aba95944619ee8 OP_EQUALVERIFY OP_CHECKSIG",
"script_hex":"76a914cba5f746dc1e41a932a7d38be7aba95944619ee888ac",
</code></pre>

<p>smartbit api has</p>

<pre><code>"script_pub_key":{
    "asm":"OP_DUP OP_HASH160 cba5f746dc1e41a932a7d38be7aba95944619ee8 OP_EQUALVERIFY OP_CHECKSIG",
    "hex":"76a914cba5f746dc1e41a932a7d38be7aba95944619ee888ac"}
</code></pre>

<p>All the apis call these two things by different names and some apis include both/one/or-the-other</p>

<hr>

<p>It would only make sense to present useful information in these apis So does it mean can I use the one with all the OP_ stuff for scriptPubKey in bitpay.com/transactionbuilder if the other is missing?</p>

<p>Why would they sometimes give me one and not the other?</p>

<p>I would have thought that if different apis give different bits of this info that maybe ether one could be used to build a transaction!?</p>

<p>For example I could strip away OP_DUP OP_HASH160 OP_EQUALVERIFY... anything beginning with OP_ (If the one with only the alpha numerical string isn't on its own i mean)</p>

<p><strong>The thing that really confused me and is the main reason:</strong></p>

<p>bitpay in their above example <code>"scriptPubKey": "a91432d272ce8a9b482b363408a0b1dd28123d59c63387"</code> is just a hex sring whereas webbtc have the exact same name <code>"scriptPubKey": "OP_DUP OP_HASH160 cba5f746dc1e41a932a7d38be7aba95944619ee8 OP_EQUALVERIFY OP_CHECKSIG"</code> but it has all the OP_ stuff in there</p>

<transactions><script><bitcore>
Confused by various apis scriptPubKey
Ben Muircroft
# Confused by various apis scriptPubKey

(Asked by: username_0 on 2016-10-01)

I am really confused and I am having trouble even asking this question in a coherent manner (as I am trying to describe things that other people have renamed multiple times in different instances) so please bear with me...

I am trying to build a transaction using each api I find so I am normalizing the structure of the response from each api call into

Bitcores expected format for the unspent outputs:

```
[
    {
      "address": "2Mwswt6Eih28xH8611fexpqKqJCLJMomveK",
      "scriptPubKey": "a91432d272ce8a9b482b363408a0b1dd28123d59c63387",
      "txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
      "vout": 1,
      "amount": 1.0,
      "confirmations":7
    }
    , { ... }
]

```

## from: <https://blog.bitpay.com/transactionbuilder/>

But different apis are returning different parts of data

webbtc.com/address api unspent has only scriptPubKey

```
"scriptPubKey": "OP_DUP OP_HASH160 cba5f746dc1e41a932a7d38be7aba95944619ee8 OP_EQUALVERIFY OP_CHECKSIG"

```

whereas toshi.io api unspent has

```
"script":"OP_DUP OP_HASH160 cba5f746dc1e41a932a7d38be7aba95944619ee8 OP_EQUALVERIFY OP_CHECKSIG",
"script_hex":"76a914cba5f746dc1e41a932a7d38be7aba95944619ee888ac",

```

smartbit api has

```
"script_pub_key":{
    "asm":"OP_DUP OP_HASH160 cba5f746dc1e41a932a7d38be7aba95944619ee8 OP_EQUALVERIFY OP_CHECKSIG",
    "hex":"76a914cba5f746dc1e41a932a7d38be7aba95944619ee888ac"}

```

All the apis call these two things by different names and some apis include both/one/or-the-other

---

It would only make sense to present useful information in these apis So does it mean can I use the one with all the OP\_ stuff for scriptPubKey in bitpay.com/transactionbuilder if the other is missing?

Why would they sometimes give me one and not the other?

I would have thought that if different apis give different bits of this info that maybe ether one could be used to build a transaction!?

For example I could strip away OP\_DUP OP\_HASH160 OP\_EQUALVERIFY... anything beginning with OP\_ (If the one with only the alpha numerical string isn't on its own i mean)

**The thing that really confused me and is the main reason:**

bitpay in their above example `"scriptPubKey": "a91432d272ce8a9b482b363408a0b1dd28123d59c63387"` is just a hex sring whereas webbtc have the exact same name `"scriptPubKey": "OP_DUP OP_HASH160 cba5f746dc1e41a932a7d38be7aba95944619ee8 OP_EQUALVERIFY OP_CHECKSIG"` but it has all the OP\_ stuff in there

**Tags:** transactions, script, bitcore


---

## 1 answers

### Answer by username_1 on 2016-10-01. Score: 4

These are API names and display scripts in their encoded and or decoded form. What you want to build a transaction is the encoded form like the one returned by toshi (script\_hex) or smartbit (hex).

A script is a sequence of instructions beginning by OP\_ (OP\_DUP, etc...) and hex data. You can read more about the Script language [here](https://en.bitcoin.it/wiki/Script).

At the protocol level, all of the instructions and data are concatenated to form a single (encoded) hex blob of the script:

```
76a914cba5f746dc1e41a932a7d38be7aba95944619ee888ac

```

This is what is signed by the transaction builder. However, it's not really intelligible for us humans. That's why these APIs decode the hex into the sequence of instructions they encode:

```
OP_DUP (0x76)
OP_HASH160 (0xa9)
(0x14 means 20 bytes of data are next)
cba5f746dc1e41a932a7d38be7aba95944619ee8
OP_EQUALVERIFY (0x88)
OP_CHECKSIG (0xac)

```

The traditional way of showing this decoded script is :

```
OP_DUP OP_HASH160 cba5f746dc1e41a932a7d38be7aba95944619ee8 OP_EQUALVERIFY OP_CHECKSIG

```

> **Comments:**
> **username_0**: So with webbtc `"scriptPubKey"` (this is protocol level script data!), Must I **encrypt** or **sign** the data with my private key in order to create the hex blob of the script?  
> **username_1**: Not you directly, that's the role of Bitpay's transaction builder. As long as you provide it the keys locking the outputs, it'll do all the signing needed to make the transaction valid.  

---

