3

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

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.

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
  • 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 Oct 1 '16 at 20:48
  • 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 Oct 1 '16 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.