<p>Sounds like <a href="https://github.com/Christewart/bitcoin/blob/e6d6a63ca60573f980a8d8a40766547acaa5bd3d/src/core_io.h#L19" rel="nofollow noreferrer">this</a> is what you are looking for</p>

<p><a href="https://github.com/Christewart/bitcoin/blob/e6d6a63ca60573f980a8d8a40766547acaa5bd3d/src/script/interpreter.cpp#L257" rel="nofollow noreferrer">Example usage</a>:</p>

<p><code>
cout &lt;&lt; "Script being executed: " &lt;&lt; ScriptToAsmStr(script) &lt;&lt; std::endl;
</code></p>

CC BY-SA 3.0
2017-02-10T16:17:44.837Z
2017-02-10T16:17:44.837Z
Chris Stewart
<p>I've got this weird string for a utx message (not my code)</p>

<pre><code>CTransaction(nVersion=1 vin=[CTxIn(prevout=COutPoint(hash=41caa5bf2b814135257b26e44b111f55c067f783e3cdf9bdf914e1ef7e403d05 n=0) scriptSig=47304402200910d62908c2f386008d024c3622cae2440338ea2f65ff970c6c4140704dadc20220636e346e716b93348aab1d01893379f21e7798870dd75d566d217784ea9e0925012103e7670f57af2bd9f601f32ea5b701140e478f0f3e06a1d23e47fc4af9d1965ae2 nSequence=4294967295), CTxIn(prevout=COutPoint(hash=e87b3bb5fd83baad8cfd621ab715b21daf44bbc6165b645f9fa1730d457623b0 n=1) scriptSig=483045022100e6429685c5a935c69659af47d2487f9252724b730eee087f75c81083ca3390860220653e3f0b53c9750c3c22d46ba0d7822e0a9661d717279ccddbfb94dfad10f330012102689f559da51e353cc1d34bd1436560b92a179646e5c5e2ae7dddf116a56656a0 nSequence=4294967295)] vout=[CTxOut(nValue=0.00061000 scriptPubKey=76a91497176e06ed3ebb9fc46d983f7e976046246b8eb388ac), CTxOut(nValue=0.03000000 scriptPubKey=76a9145414feb353a36043f5257366479389263b0cba5988ac)] nLockTime=0)
</code></pre>

<p>In each vout there is scriptPubKey that looks like a hex.</p>

<p>How to I use this information to get each vouts <strong>scriptPubKey.asm</strong> and <strong>scriptPubKey.hex</strong></p>

<p>The code that produced this string is python but I could also manipulate this data in javascript! I'm stuck on first why does the scriptPubKey(s) look like this in the first place and second what do I do to get the asm and hex information</p>

<p>I found <a href="https://github.com/bitcoin/bitcoin/blob/master/src/rpc/rawtransaction.cpp" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/blob/master/src/rpc/rawtransaction.cpp</a></p>

<pre><code>void ScriptPubKeyToJSON(const CScript&amp; scriptPubKey, UniValue&amp; out, bool fIncludeHex)
{
    txnouttype type;
    vector&lt;CTxDestination&gt; addresses;
    int nRequired;

out.push_back(Pair("asm", ScriptToAsmStr(scriptPubKey)));
if (fIncludeHex)
    out.push_back(Pair("hex", HexStr(scriptPubKey.begin(), scriptPubKey.end())));

if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) {
    out.push_back(Pair("type", GetTxnOutputType(type)));
    return;
}

out.push_back(Pair("reqSigs", nRequired));
out.push_back(Pair("type", GetTxnOutputType(type)));

UniValue a(UniValue::VARR);
BOOST_FOREACH(const CTxDestination&amp; addr, addresses)
    a.push_back(CBitcoinAddress(addr).ToString());
out.push_back(Pair("addresses", a));
</code></pre>

<p>}</p>

<p>Which looks like its doing the action I require (but I don't understand the code / what's happening)</p>

<script><utxo>
How to get asm and hex from vout
Ben Muircroft
# How to get asm and hex from vout

(Asked by: username_0 on 2017-02-09)

I've got this weird string for a utx message (not my code)

```
CTransaction(nVersion=1 vin=[CTxIn(prevout=COutPoint(hash=41caa5bf2b814135257b26e44b111f55c067f783e3cdf9bdf914e1ef7e403d05 n=0) scriptSig=47304402200910d62908c2f386008d024c3622cae2440338ea2f65ff970c6c4140704dadc20220636e346e716b93348aab1d01893379f21e7798870dd75d566d217784ea9e0925012103e7670f57af2bd9f601f32ea5b701140e478f0f3e06a1d23e47fc4af9d1965ae2 nSequence=4294967295), CTxIn(prevout=COutPoint(hash=e87b3bb5fd83baad8cfd621ab715b21daf44bbc6165b645f9fa1730d457623b0 n=1) scriptSig=483045022100e6429685c5a935c69659af47d2487f9252724b730eee087f75c81083ca3390860220653e3f0b53c9750c3c22d46ba0d7822e0a9661d717279ccddbfb94dfad10f330012102689f559da51e353cc1d34bd1436560b92a179646e5c5e2ae7dddf116a56656a0 nSequence=4294967295)] vout=[CTxOut(nValue=0.00061000 scriptPubKey=76a91497176e06ed3ebb9fc46d983f7e976046246b8eb388ac), CTxOut(nValue=0.03000000 scriptPubKey=76a9145414feb353a36043f5257366479389263b0cba5988ac)] nLockTime=0)

```

In each vout there is scriptPubKey that looks like a hex.

How to I use this information to get each vouts **scriptPubKey.asm** and **scriptPubKey.hex**

The code that produced this string is python but I could also manipulate this data in javascript! I'm stuck on first why does the scriptPubKey(s) look like this in the first place and second what do I do to get the asm and hex information

I found <https://github.com/bitcoin/bitcoin/blob/master/src/rpc/rawtransaction.cpp>

```
void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex)
{
    txnouttype type;
    vector<CTxDestination> addresses;
    int nRequired;

out.push_back(Pair("asm", ScriptToAsmStr(scriptPubKey)));
if (fIncludeHex)
    out.push_back(Pair("hex", HexStr(scriptPubKey.begin(), scriptPubKey.end())));

if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) {
    out.push_back(Pair("type", GetTxnOutputType(type)));
    return;
}

out.push_back(Pair("reqSigs", nRequired));
out.push_back(Pair("type", GetTxnOutputType(type)));

UniValue a(UniValue::VARR);
BOOST_FOREACH(const CTxDestination& addr, addresses)
    a.push_back(CBitcoinAddress(addr).ToString());
out.push_back(Pair("addresses", a));

```

}

Which looks like its doing the action I require (but I don't understand the code / what's happening)

**Tags:** script, utxo


---

## 1 answers

### Answer by username_1 on 2017-02-10. Score: 2

Sounds like [this](https://github.com/Christewart/bitcoin/blob/e6d6a63ca60573f980a8d8a40766547acaa5bd3d/src/core_io.h#L19) is what you are looking for

[Example usage](https://github.com/Christewart/bitcoin/blob/e6d6a63ca60573f980a8d8a40766547acaa5bd3d/src/script/interpreter.cpp#L257):

`cout << "Script being executed: " << ScriptToAsmStr(script) << std::endl;`


---

