user91194: My study on the scripts goes next.
I'm creating a ScriptPubKey decompiler, now I have a problem with the P2SH,
So how is calculate the key p2sh?
I using this code but I not think is correct
 string scriptHash = hex.substr(4, hex.length() - 6);

 Bytes bytes = hexBytes(scriptHash.c_str());

 char address[36];
 Base58Check::pubkeyHashToBase58Check(bytes.data(), 0x00, address);

 string stringAddr(address);

 cout << "P2SH addresss is " << address;

I have looked this code inside the class DestinationEncoder of the bitcoin core
 std::string operator()(const CKeyID& id) const
    {
        std::vector<unsigned char> data = m_params.Base58Prefix(CChainParams::PUBKEY_ADDRESS);
        data.insert(data.end(), id.begin(), id.end());
        return EncodeBase58Check(data);
    }

and with this code it seems that the information is queued to something, can you clarify my ideas?

user208: This is specified in BIP 13: https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki
You compute the Base58Check encoding of the P2SH version byte (5 for mainnet, 196 for testnet) followed by the 20-byte Hash160 of the script.
The code you're quoting is for P2PKH addresses, not P2SH.

91194: <p>My study on the scripts goes next.</p>

<p>I'm creating a ScriptPubKey decompiler, now I have a problem with the P2SH,</p>

<p>So how is calculate the key p2sh?</p>

<p>I using this code but I not think is correct</p>

<pre><code> string scriptHash = hex.substr(4, hex.length() - 6);

 Bytes bytes = hexBytes(scriptHash.c_str());

 char address[36];
 Base58Check::pubkeyHashToBase58Check(bytes.data(), 0x00, address);

 string stringAddr(address);

 cout &lt;&lt; "P2SH addresss is " &lt;&lt; address;
</code></pre>

<p>I have looked this code inside the class DestinationEncoder of the bitcoin core</p>

<pre><code> std::string operator()(const CKeyID&amp; id) const
    {
        std::vector&lt;unsigned char&gt; data = m_params.Base58Prefix(CChainParams::PUBKEY_ADDRESS);
        data.insert(data.end(), id.begin(), id.end());
        return EncodeBase58Check(data);
    }
</code></pre>

<p>and with this code it seems that the information is queued to something, can you clarify my ideas?</p>
 208: <p>This is specified in BIP 13: <a href="https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki" rel="nofollow noreferrer">https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki</a></p>

<p>You compute the Base58Check encoding of the P2SH version byte (5 for mainnet, 196 for testnet) followed by the 20-byte Hash160 of the script.</p>

<p>The code you're quoting is for P2PKH addresses, not P2SH.</p>
