<p>Your redeem script hash should be:</p>
<blockquote>
<p>RIPEMD160(SHA256(0x522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae))
= <strong>0bf37781383277cbb4e544c402f5265a51f4d828</strong></p>
</blockquote>
<p>Which results this address:</p>
<pre><code>2MtLR5mKgWRZBYtCYiSuaKpTUSuney9Cg2V
</code></pre>
<p>However you somehow end up with this hash:</p>
<blockquote>
<p><strong>c9ebaa3be1c12351c9e07ea5758a68eb20ee5098</strong></p>
</blockquote>
<p>Which results this address:</p>
<pre><code>2NBet88aY57CSYCkH7nXKb2Bxae4K3xdRBT
</code></pre>

CC BY-SA 4.0
2020-11-12T15:08:25.060Z
Thanks a lot for your answer! I did not know that I should hash the redeem script, so I am trying to replicate the steps you followed: ```hash('ripemd160', hash('sha256', '0x522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae'))``` but it returned )``` 3ad9a694cd5881032106e839f834600141b533e3)``` instead of your hash. I am using PHP but I do not think that it is my problem. Any idea?
Kevin Gravell
CC BY-SA 4.0
2020-11-12T15:10:43.037Z
About this hash ```c9ebaa3be1c12351c9e07ea5758a68eb20ee5098``` and the address ```2NBet88aY57CSYCkH7nXKb2Bxae4K3xdRBT``` it seems that it comes from the information from trannsactions in the multisig address
Kevin Gravell
CC BY-SA 4.0
2020-11-12T15:51:17.740Z
"3ad9a694cd5881032106e839f834600141b533e3" is the result of string message digest. Set "raw_output" true in order to calculate hex message digest. https://www.php.net/manual/en/function.hash.php
Brqoo
CC BY-SA 4.0
2020-11-12T20:16:51.310Z
Sorry for disturbing you again but I still do not see it. First I followed your advice and I enabled raw_out which gave me the binary output, then I converted it to hex: ```bin2hex(hash('ripemd160', hash('sha256', '0x522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae', true), true));``` but it did not return the desired value, I also tried adding and removing "0x" from the redeen script but it did not work.
Kevin Gravell
CC BY-SA 4.0
2020-11-12T20:19:19.367Z
And I tried all combinations with sha256 using raw_out and the other not etc On the other hand, I replaced my current redeemscript value for the one that you gave me ```0bf37781383277cbb4e544c402f5265a51f4d828``` but I still get the same error
Kevin Gravell
CC BY-SA 4.0
2020-11-12T21:06:50.270Z
Try:
hash('ripemd160', hex2bin(hash('sha256', hex2bin('522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae'))));
Brqoo
CC BY-SA 4.0
2020-11-13T00:31:33.787Z
Perfect! It returns the same hash you posted! :) But unfortunately when I pass the new hash as redeemscript to signtransaction function it returns the same error. I just followed the same process that I described here, but just changing the content of $redeemScript from ```522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae``` to ```0bf37781383277cbb4e544c402f5265a51f4d828```
Kevin Gravell
CC BY-SA 4.0
2020-11-12T09:02:16.527Z
2020-11-12T09:02:16.527Z
Brqoo
<p><em>2MtLR5mKgWRZBYtCYiSuaKpTUSuney9Cg2V</em> is your new address which is derived from scriptHash <code>0x0bf37781383277cbb4e544c402f5265a51f4d8289</code>. Go all the way back to step 2 and send 0.005 &amp; 0.004 to <em>2MtLR5mKgWRZBYtCYiSuaKpTUSuney9Cg2V</em>. scriptPubKey of those transactions will be both <code>OP_HASH160 0bf37781383277cbb4e544c402f5265a51f4d828 OP_EQUAL</code>.</p>
<p>Retrieve those txids like you did in step 3 to construct new spending transaction. Spending transaction will have two inputs. One unlocking 0.005 BTC, another unlocking 0.004 BTC. You need to include corresponding scriptSigs of each input that fulfils the unlocking conditions. Your unlocking condition was 2-3 multisig, so your scriptSig should look like:</p>
<pre><code>OP_0 &lt;First Signature&gt; &lt;Second Signature&gt; &lt; OP_2 &lt;First PublicKey&gt; &lt;Second PublicKey&gt; &lt;Third PublicKey&gt; OP_3 OP_CHECKMULTISIG &gt;
</code></pre>
<ol>
<li><p><code>OP_0</code> is encoded as <code>0x00</code> in hex.</p>
</li>
<li><p>Say your first DER-encoded signature is 72-bytes, plus one-byte hash code type at the end, plus one-byte length prefix at the beginning is the following:</p>
</li>
</ol>
<blockquote>
<p>49 30460221AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0221BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB 01</p>
</blockquote>
<ol start="3">
<li>Say your second DER-encoded signature is also 72-bytes, plus one-byte hash code type at the end, plus one-byte length prefix at the beginning is the following:</li>
</ol>
<blockquote>
<p>49
30460221CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC0221DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
01</p>
</blockquote>
<ol start="4">
<li><code>&lt; OP_2 &lt;First PublicKey&gt; &lt;Second PublicKey&gt; &lt;Third PublicKey&gt; OP_3 OP_CHECKMULTISIG &gt;</code> plus one-byte length  prefix is encoded in hex:</li>
</ol>
<blockquote>
<p>69
522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae</p>
</blockquote>
<p>Your scriptSig in hex will look like:</p>
<blockquote>
<p>0x004930460221AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0221BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB014930460221CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC0221DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD0169522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae</p>
</blockquote>
<p>Construct scriptSig for the other input as well. You will need to customise your php code in order to achieve all this.</p>

CC BY-SA 4.0
2020-11-14T04:15:49.973Z
Well, again thanks for taking the time to put a detailed reply. I edited my question because I followed a tutorial (I added the link at the end) where it explains how to achieve my desired result without calculating manually scripts, I found a couple of errors, the redeemscript is properly calculated now but when I try to sign the transaction it says that redeemscript/witnessscript does not match scriptPubKey... Also being honest it is being hard to follow the process using bitcoin script and DER encoding as I am new to this, but I have been reading all day about it from official website
Kevin Gravell
CC BY-SA 4.0
2020-11-14T04:17:48.360Z
By the way, do you have any email or other external way to contact you? If you accept donations I would like to send you a donation once I have it working
Kevin Gravell
CC BY-SA 4.0
2020-11-14T19:23:34.390Z
You can reach me at burak@credentialsapp.org
Brqoo
CC BY-SA 4.0
2020-11-13T09:23:06.623Z
2020-11-13T09:23:06.623Z
Brqoo
<p>I want to partially sign a rawtransactions using bitcoind through RPC but I am really stuck almost at the end of the process when I try to sign my manually created raw transaction and I spent many hours trying to find the error but I do not understand it. I am going to replicate here all the steps I did.</p>
<ol>
<li>First I create a 2-3 multisig address</li>
</ol>
<pre><code>$user1_pubkey = &quot;03e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb2&quot;;
$user2_pubkey = &quot;02df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea2946210&quot;;
$user3_pubkey = $this-&gt;bitcoin-&gt;getaddressinfo(&quot;2Msqe8jLEReQpD4CYnRj29cAqQS8c81zidv&quot;)['pubkey'];
$keys[] = $user1_pubkey;
$keys[] = $user2_pubkey;
$keys[] = $user3_pubkey;
$multisig_address = $this-&gt;bitcoin-&gt;addmultisigaddress(2, $keys);

Returned values:

[&quot;address&quot;]=&gt;
    string(35) &quot;2NBet88aY57CSYCkH7nXKb2Bxae4K3xdRBT&quot;
    [&quot;redeemScript&quot;]=&gt;
    string(210) &quot;522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae&quot;
</code></pre>
<ol start="2">
<li>I have sent two small transactions to the multisig address (one of 0.005 and another of 0.004)</li>
</ol>
<pre><code>ef669e71fb08a2dd7b9d2500a86d53ba75e41c3ab67b4ec58435904d87b749c4
8a9e837e94a639cd104631a29b57a86d55b5dc32b8372b7ec3bacdf777ba57e5
</code></pre>
<ol start="3">
<li>Now I retrieve all the information related to those txids:</li>
</ol>
<pre><code>$transaction1 = $this-&gt;bitcoin-&gt;getrawtransaction(&quot;ef669e71fb08a2dd7b9d2500a86d53ba75e41c3ab67b4ec58435904d87b749c4&quot;, true);
$transaction2 = $this-&gt;bitcoin-&gt;getrawtransaction(&quot;8a9e837e94a639cd104631a29b57a86d55b5dc32b8372b7ec3bacdf777ba57e5&quot;, true);
</code></pre>
<p>3.1. Result of previous variables:</p>
<pre><code>$transaction1 =&gt;

array(14) {
  [&quot;txid&quot;]=&gt;
  string(64) &quot;ef669e71fb08a2dd7b9d2500a86d53ba75e41c3ab67b4ec58435904d87b749c4&quot;
  [&quot;hash&quot;]=&gt;
  string(64) &quot;e586e88456cef32c01820d94541296aab85d776d890d8879184b8e70344a6353&quot;
  [&quot;version&quot;]=&gt;
  int(2)
  [&quot;size&quot;]=&gt;
  int(247)
  [&quot;vsize&quot;]=&gt;
  int(166)
  [&quot;weight&quot;]=&gt;
  int(661)
  [&quot;locktime&quot;]=&gt;
  int(1891405)
  [&quot;vin&quot;]=&gt;
  array(1) {
    [0]=&gt;
    array(5) {
      [&quot;txid&quot;]=&gt;
      string(64) &quot;9d0c2b8203b1b8f63ac8a8dc17a0e48b36efceee43d38fde50a6b3c92f811830&quot;
      [&quot;vout&quot;]=&gt;
      int(0)
      [&quot;scriptSig&quot;]=&gt;
      array(2) {
        [&quot;asm&quot;]=&gt;
        string(44) &quot;0014839c3b61637073d6aec4c74a5b2e8fe52fcc4d83&quot;
        [&quot;hex&quot;]=&gt;
        string(46) &quot;160014839c3b61637073d6aec4c74a5b2e8fe52fcc4d83&quot;
      }
      [&quot;txinwitness&quot;]=&gt;
      array(2) {
        [0]=&gt;
        string(142) &quot;3044022055bbad9ea94df56180ded2760dd77b0fc959e633b459bc906e6bd4456f72c71302201d9430ac2ed9debc9508442484accac54021c990e8906ebbf7a6b205ec9e827101&quot;
        [1]=&gt;
        string(66) &quot;0326ae8d30a90a6926b81718dfa07b0b5058636f9c86465a1c3f37b0322af023c8&quot;
      }
      [&quot;sequence&quot;]=&gt;
      int(4294967294)
    }
  }
  [&quot;vout&quot;]=&gt;
  array(2) {
    [0]=&gt;
    array(3) {
      [&quot;value&quot;]=&gt;
      float(0.005)
      [&quot;n&quot;]=&gt;
      int(0)
      [&quot;scriptPubKey&quot;]=&gt;
      array(5) {
        [&quot;asm&quot;]=&gt;
        string(60) &quot;OP_HASH160 c9ebaa3be1c12351c9e07ea5758a68eb20ee5098 OP_EQUAL&quot;
        [&quot;hex&quot;]=&gt;
        string(46) &quot;a914c9ebaa3be1c12351c9e07ea5758a68eb20ee509887&quot;
        [&quot;reqSigs&quot;]=&gt;
        int(1)
        [&quot;type&quot;]=&gt;
        string(10) &quot;scripthash&quot;
        [&quot;addresses&quot;]=&gt;
        array(1) {
          [0]=&gt;
          string(35) &quot;2NBet88aY57CSYCkH7nXKb2Bxae4K3xdRBT&quot;
        }
      }
    }
    [1]=&gt;
    array(3) {
      [&quot;value&quot;]=&gt;
      float(0.01040373)
      [&quot;n&quot;]=&gt;
      int(1)
      [&quot;scriptPubKey&quot;]=&gt;
      array(5) {
        [&quot;asm&quot;]=&gt;
        string(60) &quot;OP_HASH160 301c49c04ede304bdef0ab48e2b365a9eef737e4 OP_EQUAL&quot;
        [&quot;hex&quot;]=&gt;
        string(46) &quot;a914301c49c04ede304bdef0ab48e2b365a9eef737e487&quot;
        [&quot;reqSigs&quot;]=&gt;
        int(1)
        [&quot;type&quot;]=&gt;
        string(10) &quot;scripthash&quot;
        [&quot;addresses&quot;]=&gt;
        array(1) {
          [0]=&gt;
          string(35) &quot;2MwdcJyxRAxqQ4tf6TQSubcLMZd21MrTskx&quot;
        }
      }
    }
  }
  [&quot;hex&quot;]=&gt;
  string(494) &quot;020000000001013018812fc9b3a650de8fd343eeceef368be4a017dca8c83af6b8b103822b0c9d0000000017160014839c3b61637073d6aec4c74a5b2e8fe52fcc4d83feffffff0220a107000000000017a914c9ebaa3be1c12351c9e07ea5758a68eb20ee509887f5df0f000000000017a914301c49c04ede304bdef0ab48e2b365a9eef737e48702473044022055bbad9ea94df56180ded2760dd77b0fc959e633b459bc906e6bd4456f72c71302201d9430ac2ed9debc9508442484accac54021c990e8906ebbf7a6b205ec9e827101210326ae8d30a90a6926b81718dfa07b0b5058636f9c86465a1c3f37b0322af023c84ddc1c00&quot;
  [&quot;blockhash&quot;]=&gt;
  string(64) &quot;00000000b1c75e4431f9c23a75779c964fa51cd714f9703781670f1a2c50a8c7&quot;
  [&quot;confirmations&quot;]=&gt;
  int(388)
  [&quot;time&quot;]=&gt;
  int(1605141275)
  [&quot;blocktime&quot;]=&gt;
  int(1605141275)
}


$transaction2 =&gt;

array(14) {
  [&quot;txid&quot;]=&gt;
  string(64) &quot;8a9e837e94a639cd104631a29b57a86d55b5dc32b8372b7ec3bacdf777ba57e5&quot;
  [&quot;hash&quot;]=&gt;
  string(64) &quot;0e8dfd742d3ea5f12ee7c033112f5e6f585b41e317b3f9d3fef61db4200c4bbd&quot;
  [&quot;version&quot;]=&gt;
  int(2)
  [&quot;size&quot;]=&gt;
  int(247)
  [&quot;vsize&quot;]=&gt;
  int(166)
  [&quot;weight&quot;]=&gt;
  int(661)
  [&quot;locktime&quot;]=&gt;
  int(1891405)
  [&quot;vin&quot;]=&gt;
  array(1) {
    [0]=&gt;
    array(5) {
      [&quot;txid&quot;]=&gt;
      string(64) &quot;ef669e71fb08a2dd7b9d2500a86d53ba75e41c3ab67b4ec58435904d87b749c4&quot;
      [&quot;vout&quot;]=&gt;
      int(1)
      [&quot;scriptSig&quot;]=&gt;
      array(2) {
        [&quot;asm&quot;]=&gt;
        string(44) &quot;0014c7f49ae39660b15632f46a3c69a67ccb4de7dc20&quot;
        [&quot;hex&quot;]=&gt;
        string(46) &quot;160014c7f49ae39660b15632f46a3c69a67ccb4de7dc20&quot;
      }
      [&quot;txinwitness&quot;]=&gt;
      array(2) {
        [0]=&gt;
        string(142) &quot;304402207cc7558274cd9458c44bf7554d0b049bba1388cd82057b3f8d0786bc28690aad022057eea44e01ff11c608e254a844b620f428fb515db6ef33cd199c57d3008ce89c01&quot;
        [1]=&gt;
        string(66) &quot;0303c01176f2db9efaa18e169e0ea7da87784208e05fcb1e0258ccb834805ed02d&quot;
      }
      [&quot;sequence&quot;]=&gt;
      int(4294967294)
    }
  }
  [&quot;vout&quot;]=&gt;
  array(2) {
    [0]=&gt;
    array(3) {
      [&quot;value&quot;]=&gt;
      float(0.004)
      [&quot;n&quot;]=&gt;
      int(0)
      [&quot;scriptPubKey&quot;]=&gt;
      array(5) {
        [&quot;asm&quot;]=&gt;
        string(60) &quot;OP_HASH160 c9ebaa3be1c12351c9e07ea5758a68eb20ee5098 OP_EQUAL&quot;
        [&quot;hex&quot;]=&gt;
        string(46) &quot;a914c9ebaa3be1c12351c9e07ea5758a68eb20ee509887&quot;
        [&quot;reqSigs&quot;]=&gt;
        int(1)
        [&quot;type&quot;]=&gt;
        string(10) &quot;scripthash&quot;
        [&quot;addresses&quot;]=&gt;
        array(1) {
          [0]=&gt;
          string(35) &quot;2NBet88aY57CSYCkH7nXKb2Bxae4K3xdRBT&quot;
        }
      }
    }
    [1]=&gt;
    array(3) {
      [&quot;value&quot;]=&gt;
      float(0.00640207)
      [&quot;n&quot;]=&gt;
      int(1)
      [&quot;scriptPubKey&quot;]=&gt;
      array(5) {
        [&quot;asm&quot;]=&gt;
        string(60) &quot;OP_HASH160 0f670955696f3835ef9204dad881b1c9f3002cc7 OP_EQUAL&quot;
        [&quot;hex&quot;]=&gt;
        string(46) &quot;a9140f670955696f3835ef9204dad881b1c9f3002cc787&quot;
        [&quot;reqSigs&quot;]=&gt;
        int(1)
        [&quot;type&quot;]=&gt;
        string(10) &quot;scripthash&quot;
        [&quot;addresses&quot;]=&gt;
        array(1) {
          [0]=&gt;
          string(35) &quot;2MtefZG3K2Zs38dYntJwJKg1WqSEqNoW9sF&quot;
        }
      }
    }
  }
  [&quot;hex&quot;]=&gt;
  string(494) &quot;02000000000101c449b7874d903584c54e7bb63a1ce475ba536da800259d7bdda208fb719e66ef0100000017160014c7f49ae39660b15632f46a3c69a67ccb4de7dc20feffffff02801a06000000000017a914c9ebaa3be1c12351c9e07ea5758a68eb20ee509887cfc409000000000017a9140f670955696f3835ef9204dad881b1c9f3002cc7870247304402207cc7558274cd9458c44bf7554d0b049bba1388cd82057b3f8d0786bc28690aad022057eea44e01ff11c608e254a844b620f428fb515db6ef33cd199c57d3008ce89c01210303c01176f2db9efaa18e169e0ea7da87784208e05fcb1e0258ccb834805ed02d4ddc1c00&quot;
  [&quot;blockhash&quot;]=&gt;
  string(64) &quot;00000000b1c75e4431f9c23a75779c964fa51cd714f9703781670f1a2c50a8c7&quot;
  [&quot;confirmations&quot;]=&gt;
  int(388)
  [&quot;time&quot;]=&gt;
  int(1605141275)
  [&quot;blocktime&quot;]=&gt;
  int(1605141275)
}

</code></pre>
<ol start="4">
<li>I want to create a raw transaction to spend both utxos and I want to spent it in two different address. So having in mind the fee for the transaction I proceed to create manually the transaction.</li>
</ol>
<pre><code>        $fee = number_format(floatval($this-&gt;bitcoin-&gt;estimateSmartFee(6)['feerate'])/5, 8);
        $raw_amount = 0.00000000;
        $txids = [];
        $vouts = [];
        $amounts = [];
        $scriptPubs = [];
        for($i=0; $i&lt;count($transactions); $i++){
            $total_amount+=$transactions[$i][&quot;vout&quot;][0][&quot;value&quot;];
            $txids[] = $transactions[$i][&quot;txid&quot;];
            $vouts[] = $transactions[$i][&quot;vout&quot;][0][&quot;n&quot;];
            $amounts[] = $transactions[$i][&quot;vout&quot;][0][&quot;value&quot;];
            $scriptPubs[] = $transactions[$i][&quot;vout&quot;][0][&quot;scriptPubKey&quot;][&quot;hex&quot;];
        }

        $inputs = '[';
        for($i=0; $i&lt;count($vouts); $i++){
            $inputs.='{
                        &quot;txid&quot;: &quot;'.$txids[$i].'&quot;,
                        &quot;vout&quot;: '.$vouts[$i].'
                      }';
            if($i+1!=count($vouts)){
                $inputs.=',';
            }
        }
        $inputs.=']';

        $minus_fee = $raw_amount-floatval($fee);
        $amount1 = $minus_fee*0.6;
        $amount2 = $minus_fee*0.4;

        $address1 = &quot;tb1qhjcqny2rvaqd7q0700m968e3vuqctmuhhyk9fk&quot;;
        $address2 = &quot;tb1q2nrysxf8nwxv8euwtu470wgjruw25guxkal3wd&quot;;
        $outputs = '{
                      &quot;'.$address1.'&quot;: '.$amount1.',
                      &quot;'.$address2.'&quot;: '.$amount2.'
                    }';

        $raw_transaction = $this-&gt;bitcoin-&gt;createrawtransaction(json_decode($inputs), json_decode($outputs));
</code></pre>
<p>4.1. Result of $raw_transaction is the following:</p>
<pre><code>0200000002c449b7874d903584c54e7bb63a1ce475ba536da800259d7bdda208fb719e66ef0000000000ffffffffe557ba77f7cdbac37e2b37b832dcb5556da8579ba2314610cd39a6947e839e8a0000000000ffffffff02e83c080000000000160014bcb00991436740df01fe7bf65d1f31670185ef97f07d050000000000160014b92b9f7f7bf6e4e1cdd73d3d23a1dbc98aa57d4e00000000
</code></pre>
<ol start="5">
<li>I decode $raw_transaction</li>
</ol>
<pre><code>$decoded = $this-&gt;bitcoin-&gt;decoderawtransaction($raw_transaction);
</code></pre>
<p>Content of $decoded:</p>
<pre><code>array(9) {
  [&quot;txid&quot;]=&gt;
  string(64) &quot;ba11b2caf11d79c1f4bc349f40895c380218e9ab91ec4c1d52aaee8284749549&quot;
  [&quot;hash&quot;]=&gt;
  string(64) &quot;ba11b2caf11d79c1f4bc349f40895c380218e9ab91ec4c1d52aaee8284749549&quot;
  [&quot;version&quot;]=&gt;
  int(2)
  [&quot;size&quot;]=&gt;
  int(154)
  [&quot;vsize&quot;]=&gt;
  int(154)
  [&quot;weight&quot;]=&gt;
  int(616)
  [&quot;locktime&quot;]=&gt;
  int(0)
  [&quot;vin&quot;]=&gt;
  array(2) {
    [0]=&gt;
    array(4) {
      [&quot;txid&quot;]=&gt;
      string(64) &quot;ef669e71fb08a2dd7b9d2500a86d53ba75e41c3ab67b4ec58435904d87b749c4&quot;
      [&quot;vout&quot;]=&gt;
      int(0)
      [&quot;scriptSig&quot;]=&gt;
      array(2) {
        [&quot;asm&quot;]=&gt;
        string(0) &quot;&quot;
        [&quot;hex&quot;]=&gt;
        string(0) &quot;&quot;
      }
      [&quot;sequence&quot;]=&gt;
      int(4294967295)
    }
    [1]=&gt;
    array(4) {
      [&quot;txid&quot;]=&gt;
      string(64) &quot;8a9e837e94a639cd104631a29b57a86d55b5dc32b8372b7ec3bacdf777ba57e5&quot;
      [&quot;vout&quot;]=&gt;
      int(0)
      [&quot;scriptSig&quot;]=&gt;
      array(2) {
        [&quot;asm&quot;]=&gt;
        string(0) &quot;&quot;
        [&quot;hex&quot;]=&gt;
        string(0) &quot;&quot;
      }
      [&quot;sequence&quot;]=&gt;
      int(4294967295)
    }
  }
  [&quot;vout&quot;]=&gt;
  array(2) {
    [0]=&gt;
    array(3) {
      [&quot;value&quot;]=&gt;
      float(0.0053988)
      [&quot;n&quot;]=&gt;
      int(0)
      [&quot;scriptPubKey&quot;]=&gt;
      array(5) {
        [&quot;asm&quot;]=&gt;
        string(42) &quot;0 bcb00991436740df01fe7bf65d1f31670185ef97&quot;
        [&quot;hex&quot;]=&gt;
        string(44) &quot;0014bcb00991436740df01fe7bf65d1f31670185ef97&quot;
        [&quot;reqSigs&quot;]=&gt;
        int(1)
        [&quot;type&quot;]=&gt;
        string(18) &quot;witness_v0_keyhash&quot;
        [&quot;addresses&quot;]=&gt;
        array(1) {
          [0]=&gt;
          string(42) &quot;tb1qhjcqny2rvaqd7q0700m968e3vuqctmuhhyk9fk&quot;
        }
      }
    }
    [1]=&gt;
    array(3) {
      [&quot;value&quot;]=&gt;
      float(0.0035992)
      [&quot;n&quot;]=&gt;
      int(1)
      [&quot;scriptPubKey&quot;]=&gt;
      array(5) {
        [&quot;asm&quot;]=&gt;
        string(42) &quot;0 b92b9f7f7bf6e4e1cdd73d3d23a1dbc98aa57d4e&quot;
        [&quot;hex&quot;]=&gt;
        string(44) &quot;0014b92b9f7f7bf6e4e1cdd73d3d23a1dbc98aa57d4e&quot;
        [&quot;reqSigs&quot;]=&gt;
        int(1)
        [&quot;type&quot;]=&gt;
        string(18) &quot;witness_v0_keyhash&quot;
        [&quot;addresses&quot;]=&gt;
        array(1) {
          [0]=&gt;
          string(42) &quot;tb1qhy4e7lmm7mjwrnwh857j8gwmex922l2wwc830y&quot;
        }
      }
    }
  }
}
</code></pre>
<ol start="6">
<li>Now I proceed to partially sign the previous created transaction.</li>
</ol>
<pre><code>        $private_key = $this-&gt;bitcoin-&gt;dumpprivkey(&quot;2Msqe8jLEReQpD4CYnRj29cAqQS8c81zidv&quot;); // cS6e5CojfNy2ELWcsB4tLFVQV9wSSQUw1PU4YrSwRSjYLaC8ikrU
        $redeemScript = &quot;522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae&quot;;
        $vin = $raw_transaction[&quot;vin&quot;];
        $vout = $raw_transaction[&quot;vout&quot;];

        $prevtxs = '[';
        for($i=0; $i&lt;count($txids); $i++){
            $prevtxs .= '{
                    &quot;txid&quot;: &quot;'.$txids[$i].'&quot;,
                    &quot;vout&quot;: '.$vouts[$i].',
                    &quot;scriptPubKey&quot;: &quot;'.$scriptPubs[$i].'&quot;, 
                    &quot;redeemScript&quot;: &quot;'.$redeemScript.'&quot;,
                    &quot;amount&quot;: '.$amounts[$i].'
                  }';
            if($i+1!=count($txids)){
                $json2.=',';
            }
        }
        $prevtxs.=']';

        $partially_signed = $this-&gt;bitcoin-&gt;signrawtransactionwithkey($raw_transaction, json_decode($private_key), json_decode($prevtxs));
</code></pre>
<ol start="7">
<li>And in the previous step is where the process fails. The transaction is not signed and the bitcoind returns this error:</li>
</ol>
<pre><code>redeemScript/witnessScript does not match scriptPubKey
</code></pre>
<p>I am using bitcoin testnet to test it and I think that I added all the information. If someone knows where it is the mistake, please let me know. I searched information to fix it but I could not find a solution for my issue.</p>
<p>Edited:
I followed the next <a href="https://btcinformation.org/en/developer-examples#p2sh-multisig" rel="nofollow noreferrer">tutorial</a> where I could notice that I was using the wrong scriptpub and I retrieved funding inputs using getrawtransaction passing the second argument (true) to get the decoded transaction. And well, now the previous error is gone but now it throws a new error: <code>redeemScript/witnessScript does not match scriptPubKey</code></p>
<p>Thanks</p>

<bitcoin-core><bitcoind><multi-signature><createrawtransaction><signrawtransaction>
Partially Signing multisig rawtransaction returns redeemScript/witnessScript does not match scriptPubKey
Kevin Gravell
# Partially Signing multisig rawtransaction returns redeemScript/witnessScript does not match scriptPubKey

(Asked by: username_0 on 2020-11-12)

I want to partially sign a rawtransactions using bitcoind through RPC but I am really stuck almost at the end of the process when I try to sign my manually created raw transaction and I spent many hours trying to find the error but I do not understand it. I am going to replicate here all the steps I did.

First I create a 2-3 multisig address

$user1_pubkey = "03e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb2";
$user2_pubkey = "02df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea2946210";
$user3_pubkey = $this->bitcoin->getaddressinfo("2Msqe8jLEReQpD4CYnRj29cAqQS8c81zidv")['pubkey'];
$keys[] = $user1_pubkey;
$keys[] = $user2_pubkey;
$keys[] = $user3_pubkey;
$multisig_address = $this->bitcoin->addmultisigaddress(2, $keys);

Returned values:

["address"]=>
    string(35) "2NBet88aY57CSYCkH7nXKb2Bxae4K3xdRBT"
    ["redeemScript"]=>
    string(210) "522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae"


I have sent two small transactions to the multisig address (one of 0.005 and another of 0.004)

ef669e71fb08a2dd7b9d2500a86d53ba75e41c3ab67b4ec58435904d87b749c4
8a9e837e94a639cd104631a29b57a86d55b5dc32b8372b7ec3bacdf777ba57e5


Now I retrieve all the information related to those txids:

$transaction1 = $this->bitcoin->getrawtransaction("ef669e71fb08a2dd7b9d2500a86d53ba75e41c3ab67b4ec58435904d87b749c4", true);
$transaction2 = $this->bitcoin->getrawtransaction("8a9e837e94a639cd104631a29b57a86d55b5dc32b8372b7ec3bacdf777ba57e5", true);

3.1. Result of previous variables:
$transaction1 =>

array(14) {
  ["txid"]=>
  string(64) "ef669e71fb08a2dd7b9d2500a86d53ba75e41c3ab67b4ec58435904d87b749c4"
  ["hash"]=>
  string(64) "e586e88456cef32c01820d94541296aab85d776d890d8879184b8e70344a6353"
  ["version"]=>
  int(2)
  ["size"]=>
  int(247)
  ["vsize"]=>
  int(166)
  ["weight"]=>
  int(661)
  ["locktime"]=>
  int(1891405)
  ["vin"]=>
  array(1) {
    [0]=>
    array(5) {
      ["txid"]=>
      string(64) "9d0c2b8203b1b8f63ac8a8dc17a0e48b36efceee43d38fde50a6b3c92f811830"
      ["vout"]=>
      int(0)
      ["scriptSig"]=>
      array(2) {
        ["asm"]=>
        string(44) "0014839c3b61637073d6aec4c74a5b2e8fe52fcc4d83"
        ["hex"]=>
        string(46) "160014839c3b61637073d6aec4c74a5b2e8fe52fcc4d83"
      }
      ["txinwitness"]=>
      array(2) {
        [0]=>
        string(142) "3044022055bbad9ea94df56180ded2760dd77b0fc959e633b459bc906e6bd4456f72c71302201d9430ac2ed9debc9508442484accac54021c990e8906ebbf7a6b205ec9e827101"
        [1]=>
        string(66) "0326ae8d30a90a6926b81718dfa07b0b5058636f9c86465a1c3f37b0322af023c8"
      }
      ["sequence"]=>
      int(4294967294)
    }
  }
  ["vout"]=>
  array(2) {
    [0]=>
    array(3) {
      ["value"]=>
      float(0.005)
      ["n"]=>
      int(0)
      ["scriptPubKey"]=>
      array(5) {
        ["asm"]=>
        string(60) "OP_HASH160 c9ebaa3be1c12351c9e07ea5758a68eb20ee5098 OP_EQUAL"
        ["hex"]=>
        string(46) "a914c9ebaa3be1c12351c9e07ea5758a68eb20ee509887"
        ["reqSigs"]=>
        int(1)
        ["type"]=>
        string(10) "scripthash"
        ["addresses"]=>
        array(1) {
          [0]=>
          string(35) "2NBet88aY57CSYCkH7nXKb2Bxae4K3xdRBT"
        }
      }
    }
    [1]=>
    array(3) {
      ["value"]=>
      float(0.01040373)
      ["n"]=>
      int(1)
      ["scriptPubKey"]=>
      array(5) {
        ["asm"]=>
        string(60) "OP_HASH160 301c49c04ede304bdef0ab48e2b365a9eef737e4 OP_EQUAL"
        ["hex"]=>
        string(46) "a914301c49c04ede304bdef0ab48e2b365a9eef737e487"
        ["reqSigs"]=>
        int(1)
        ["type"]=>
        string(10) "scripthash"
        ["addresses"]=>
        array(1) {
          [0]=>
          string(35) "2MwdcJyxRAxqQ4tf6TQSubcLMZd21MrTskx"
        }
      }
    }
  }
  ["hex"]=>
  string(494) "020000000001013018812fc9b3a650de8fd343eeceef368be4a017dca8c83af6b8b103822b0c9d0000000017160014839c3b61637073d6aec4c74a5b2e8fe52fcc4d83feffffff0220a107000000000017a914c9ebaa3be1c12351c9e07ea5758a68eb20ee509887f5df0f000000000017a914301c49c04ede304bdef0ab48e2b365a9eef737e48702473044022055bbad9ea94df56180ded2760dd77b0fc959e633b459bc906e6bd4456f72c71302201d9430ac2ed9debc9508442484accac54021c990e8906ebbf7a6b205ec9e827101210326ae8d30a90a6926b81718dfa07b0b5058636f9c86465a1c3f37b0322af023c84ddc1c00"
  ["blockhash"]=>
  string(64) "00000000b1c75e4431f9c23a75779c964fa51cd714f9703781670f1a2c50a8c7"
  ["confirmations"]=>
  int(388)
  ["time"]=>
  int(1605141275)
  ["blocktime"]=>
  int(1605141275)
}


$transaction2 =>

array(14) {
  ["txid"]=>
  string(64) "8a9e837e94a639cd104631a29b57a86d55b5dc32b8372b7ec3bacdf777ba57e5"
  ["hash"]=>
  string(64) "0e8dfd742d3ea5f12ee7c033112f5e6f585b41e317b3f9d3fef61db4200c4bbd"
  ["version"]=>
  int(2)
  ["size"]=>
  int(247)
  ["vsize"]=>
  int(166)
  ["weight"]=>
  int(661)
  ["locktime"]=>
  int(1891405)
  ["vin"]=>
  array(1) {
    [0]=>
    array(5) {
      ["txid"]=>
      string(64) "ef669e71fb08a2dd7b9d2500a86d53ba75e41c3ab67b4ec58435904d87b749c4"
      ["vout"]=>
      int(1)
      ["scriptSig"]=>
      array(2) {
        ["asm"]=>
        string(44) "0014c7f49ae39660b15632f46a3c69a67ccb4de7dc20"
        ["hex"]=>
        string(46) "160014c7f49ae39660b15632f46a3c69a67ccb4de7dc20"
      }
      ["txinwitness"]=>
      array(2) {
        [0]=>
        string(142) "304402207cc7558274cd9458c44bf7554d0b049bba1388cd82057b3f8d0786bc28690aad022057eea44e01ff11c608e254a844b620f428fb515db6ef33cd199c57d3008ce89c01"
        [1]=>
        string(66) "0303c01176f2db9efaa18e169e0ea7da87784208e05fcb1e0258ccb834805ed02d"
      }
      ["sequence"]=>
      int(4294967294)
    }
  }
  ["vout"]=>
  array(2) {
    [0]=>
    array(3) {
      ["value"]=>
      float(0.004)
      ["n"]=>
      int(0)
      ["scriptPubKey"]=>
      array(5) {
        ["asm"]=>
        string(60) "OP_HASH160 c9ebaa3be1c12351c9e07ea5758a68eb20ee5098 OP_EQUAL"
        ["hex"]=>
        string(46) "a914c9ebaa3be1c12351c9e07ea5758a68eb20ee509887"
        ["reqSigs"]=>
        int(1)
        ["type"]=>
        string(10) "scripthash"
        ["addresses"]=>
        array(1) {
          [0]=>
          string(35) "2NBet88aY57CSYCkH7nXKb2Bxae4K3xdRBT"
        }
      }
    }
    [1]=>
    array(3) {
      ["value"]=>
      float(0.00640207)
      ["n"]=>
      int(1)
      ["scriptPubKey"]=>
      array(5) {
        ["asm"]=>
        string(60) "OP_HASH160 0f670955696f3835ef9204dad881b1c9f3002cc7 OP_EQUAL"
        ["hex"]=>
        string(46) "a9140f670955696f3835ef9204dad881b1c9f3002cc787"
        ["reqSigs"]=>
        int(1)
        ["type"]=>
        string(10) "scripthash"
        ["addresses"]=>
        array(1) {
          [0]=>
          string(35) "2MtefZG3K2Zs38dYntJwJKg1WqSEqNoW9sF"
        }
      }
    }
  }
  ["hex"]=>
  string(494) "02000000000101c449b7874d903584c54e7bb63a1ce475ba536da800259d7bdda208fb719e66ef0100000017160014c7f49ae39660b15632f46a3c69a67ccb4de7dc20feffffff02801a06000000000017a914c9ebaa3be1c12351c9e07ea5758a68eb20ee509887cfc409000000000017a9140f670955696f3835ef9204dad881b1c9f3002cc7870247304402207cc7558274cd9458c44bf7554d0b049bba1388cd82057b3f8d0786bc28690aad022057eea44e01ff11c608e254a844b620f428fb515db6ef33cd199c57d3008ce89c01210303c01176f2db9efaa18e169e0ea7da87784208e05fcb1e0258ccb834805ed02d4ddc1c00"
  ["blockhash"]=>
  string(64) "00000000b1c75e4431f9c23a75779c964fa51cd714f9703781670f1a2c50a8c7"
  ["confirmations"]=>
  int(388)
  ["time"]=>
  int(1605141275)
  ["blocktime"]=>
  int(1605141275)
}



I want to create a raw transaction to spend both utxos and I want to spent it in two different address. So having in mind the fee for the transaction I proceed to create manually the transaction.

        $fee = number_format(floatval($this->bitcoin->estimateSmartFee(6)['feerate'])/5, 8);
        $raw_amount = 0.00000000;
        $txids = [];
        $vouts = [];
        $amounts = [];
        $scriptPubs = [];
        for($i=0; $ibitcoin->createrawtransaction(json_decode($inputs), json_decode($outputs));

4.1. Result of $raw_transaction is the following:
0200000002c449b7874d903584c54e7bb63a1ce475ba536da800259d7bdda208fb719e66ef0000000000ffffffffe557ba77f7cdbac37e2b37b832dcb5556da8579ba2314610cd39a6947e839e8a0000000000ffffffff02e83c080000000000160014bcb00991436740df01fe7bf65d1f31670185ef97f07d050000000000160014b92b9f7f7bf6e4e1cdd73d3d23a1dbc98aa57d4e00000000


I decode $raw_transaction

$decoded = $this->bitcoin->decoderawtransaction($raw_transaction);

Content of $decoded:
array(9) {
  ["txid"]=>
  string(64) "ba11b2caf11d79c1f4bc349f40895c380218e9ab91ec4c1d52aaee8284749549"
  ["hash"]=>
  string(64) "ba11b2caf11d79c1f4bc349f40895c380218e9ab91ec4c1d52aaee8284749549"
  ["version"]=>
  int(2)
  ["size"]=>
  int(154)
  ["vsize"]=>
  int(154)
  ["weight"]=>
  int(616)
  ["locktime"]=>
  int(0)
  ["vin"]=>
  array(2) {
    [0]=>
    array(4) {
      ["txid"]=>
      string(64) "ef669e71fb08a2dd7b9d2500a86d53ba75e41c3ab67b4ec58435904d87b749c4"
      ["vout"]=>
      int(0)
      ["scriptSig"]=>
      array(2) {
        ["asm"]=>
        string(0) ""
        ["hex"]=>
        string(0) ""
      }
      ["sequence"]=>
      int(4294967295)
    }
    [1]=>
    array(4) {
      ["txid"]=>
      string(64) "8a9e837e94a639cd104631a29b57a86d55b5dc32b8372b7ec3bacdf777ba57e5"
      ["vout"]=>
      int(0)
      ["scriptSig"]=>
      array(2) {
        ["asm"]=>
        string(0) ""
        ["hex"]=>
        string(0) ""
      }
      ["sequence"]=>
      int(4294967295)
    }
  }
  ["vout"]=>
  array(2) {
    [0]=>
    array(3) {
      ["value"]=>
      float(0.0053988)
      ["n"]=>
      int(0)
      ["scriptPubKey"]=>
      array(5) {
        ["asm"]=>
        string(42) "0 bcb00991436740df01fe7bf65d1f31670185ef97"
        ["hex"]=>
        string(44) "0014bcb00991436740df01fe7bf65d1f31670185ef97"
        ["reqSigs"]=>
        int(1)
        ["type"]=>
        string(18) "witness_v0_keyhash"
        ["addresses"]=>
        array(1) {
          [0]=>
          string(42) "tb1qhjcqny2rvaqd7q0700m968e3vuqctmuhhyk9fk"
        }
      }
    }
    [1]=>
    array(3) {
      ["value"]=>
      float(0.0035992)
      ["n"]=>
      int(1)
      ["scriptPubKey"]=>
      array(5) {
        ["asm"]=>
        string(42) "0 b92b9f7f7bf6e4e1cdd73d3d23a1dbc98aa57d4e"
        ["hex"]=>
        string(44) "0014b92b9f7f7bf6e4e1cdd73d3d23a1dbc98aa57d4e"
        ["reqSigs"]=>
        int(1)
        ["type"]=>
        string(18) "witness_v0_keyhash"
        ["addresses"]=>
        array(1) {
          [0]=>
          string(42) "tb1qhy4e7lmm7mjwrnwh857j8gwmex922l2wwc830y"
        }
      }
    }
  }
}


Now I proceed to partially sign the previous created transaction.

        $private_key = $this->bitcoin->dumpprivkey("2Msqe8jLEReQpD4CYnRj29cAqQS8c81zidv"); // cS6e5CojfNy2ELWcsB4tLFVQV9wSSQUw1PU4YrSwRSjYLaC8ikrU
        $redeemScript = "522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae";
        $vin = $raw_transaction["vin"];
        $vout = $raw_transaction["vout"];

        $prevtxs = '[';
        for($i=0; $ibitcoin->signrawtransactionwithkey($raw_transaction, json_decode($private_key), json_decode($prevtxs));


And in the previous step is where the process fails. The transaction is not signed and the bitcoind returns this error:

redeemScript/witnessScript does not match scriptPubKey

I am using bitcoin testnet to test it and I think that I added all the information. If someone knows where it is the mistake, please let me know. I searched information to fix it but I could not find a solution for my issue.
Edited:
I followed the next tutorial where I could notice that I was using the wrong scriptpub and I retrieved funding inputs using getrawtransaction passing the second argument (true) to get the decoded transaction. And well, now the previous error is gone but now it throws a new error: redeemScript/witnessScript does not match scriptPubKey
Thanks

**Tags:** bitcoin-core, bitcoind, multi-signature, createrawtransaction, signrawtransaction


---

## 2 answers

### Answer by username_1 on 2020-11-12. Score: 1

Your redeem script hash should be:

RIPEMD160(SHA256(0x522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae))
= 0bf37781383277cbb4e544c402f5265a51f4d828

Which results this address:
2MtLR5mKgWRZBYtCYiSuaKpTUSuney9Cg2V

However you somehow end up with this hash:

c9ebaa3be1c12351c9e07ea5758a68eb20ee5098

Which results this address:
2NBet88aY57CSYCkH7nXKb2Bxae4K3xdRBT

> **Comments:**
> **username_0**: Thanks a lot for your answer! I did not know that I should hash the redeem script, so I am trying to replicate the steps you followed: ```hash('ripemd160', hash('sha256', '0x522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae'))``` but it returned )``` 3ad9a694cd5881032106e839f834600141b533e3)``` instead of your hash. I am using PHP but I do not think that it is my problem. Any idea?  
> **username_0**: About this hash ```c9ebaa3be1c12351c9e07ea5758a68eb20ee5098``` and the address ```2NBet88aY57CSYCkH7nXKb2Bxae4K3xdRBT``` it seems that it comes from the information from trannsactions in the multisig address  
> **username_1**: "3ad9a694cd5881032106e839f834600141b533e3" is the result of string message digest. Set "raw_output" true in order to calculate hex message digest. https://www.php.net/manual/en/function.hash.php  
> **username_0**: Sorry for disturbing you again but I still do not see it. First I followed your advice and I enabled raw_out which gave me the binary output, then I converted it to hex: ```bin2hex(hash('ripemd160', hash('sha256', '0x522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae', true), true));``` but it did not return the desired value, I also tried adding and removing "0x" from the redeen script but it did not work.  
> **username_0**: And I tried all combinations with sha256 using raw_out and the other not etc On the other hand, I replaced my current redeemscript value for the one that you gave me ```0bf37781383277cbb4e544c402f5265a51f4d828``` but I still get the same error  
> **username_1**: Try: hash('ripemd160', hex2bin(hash('sha256', hex2bin('522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae'))));  
> **username_0**: Perfect! It returns the same hash you posted! :) But unfortunately when I pass the new hash as redeemscript to signtransaction function it returns the same error. I just followed the same process that I described here, but just changing the content of $redeemScript from ```522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae``` to ```0bf37781383277cbb4e544c402f5265a51f4d828```  

---

### Answer by username_1 on 2020-11-13. Score: 0

2MtLR5mKgWRZBYtCYiSuaKpTUSuney9Cg2V is your new address which is derived from scriptHash 0x0bf37781383277cbb4e544c402f5265a51f4d8289. Go all the way back to step 2 and send 0.005 & 0.004 to 2MtLR5mKgWRZBYtCYiSuaKpTUSuney9Cg2V. scriptPubKey of those transactions will be both OP_HASH160 0bf37781383277cbb4e544c402f5265a51f4d828 OP_EQUAL.
Retrieve those txids like you did in step 3 to construct new spending transaction. Spending transaction will have two inputs. One unlocking 0.005 BTC, another unlocking 0.004 BTC. You need to include corresponding scriptSigs of each input that fulfils the unlocking conditions. Your unlocking condition was 2-3 multisig, so your scriptSig should look like:
OP_0   < OP_2    OP_3 OP_CHECKMULTISIG >


OP_0 is encoded as 0x00 in hex.

Say your first DER-encoded signature is 72-bytes, plus one-byte hash code type at the end, plus one-byte length prefix at the beginning is the following:



49 30460221AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0221BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB 01


Say your second DER-encoded signature is also 72-bytes, plus one-byte hash code type at the end, plus one-byte length prefix at the beginning is the following:


49
30460221CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC0221DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
01


< OP_2    OP_3 OP_CHECKMULTISIG > plus one-byte length  prefix is encoded in hex:


69
522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae

Your scriptSig in hex will look like:

0x004930460221AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0221BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB014930460221CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC0221DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD0169522103e33af80b92e4efd64852166d6126e10aafdcc741579c67c6aa9eb89080cebeb22102df4bf6a54f79b333b7796d2941de13b1755c00c09f4dbf696c7729aea29462102102c099a12b6cba679ad56d8e793847f422634bc84b42cb3fae0b00a6943f56921253ae

Construct scriptSig for the other input as well. You will need to customise your php code in order to achieve all this.

> **Comments:**
> **username_0**: Well, again thanks for taking the time to put a detailed reply. I edited my question because I followed a tutorial (I added the link at the end) where it explains how to achieve my desired result without calculating manually scripts, I found a couple of errors, the redeemscript is properly calculated now but when I try to sign the transaction it says that redeemscript/witnessscript does not match scriptPubKey... Also being honest it is being hard to follow the process using bitcoin script and DER encoding as I am new to this, but I have been reading all day about it from official website  
> **username_0**: By the way, do you have any email or other external way to contact you? If you accept donations I would like to send you a donation once I have it working  
> **username_1**: You can reach me at burak@credentialsapp.org  

---

