title: PHP Bitwasp, signing a bitcoin-cash transaction
body: <p>I try to sign test bitcoin-cash transaction, and then broadcast.
  For bitwasp version 0.0.35.0, the code is:</p>
  
  <pre><code>   $utxoOwnerPrivateKey = 'MyPrIvAtEKey';//public key is "16Dbmp13CqdLVwjXrd6amF48t7L8gYSGBj", note - the real private key is another
     $utxo = '5e44cdab9cb4a4f1871f2137ab568bf9ef2760e52816971fbaf0198f19e28378';
     $utxoAmount = 598558;
     $reciverPublicKey = '1EjCxux1FcohsBNGzY9KdF59Dz7MYHQyPN';
     $fee = 1000;
  
     $addressCreator = new \Btccom\BitcoinCash\Address\AddressCreator();
  
     $networkObject = \Btccom\BitcoinCash\Network\NetworkFactory::bitcoinCash();
     $keyPairInput = \BitWasp\Bitcoin\Key\PrivateKeyFactory::fromWif($utxoOwnerPrivateKey, null, $networkObject);
  
  
     $outpoint = new \BitWasp\Bitcoin\Transaction\OutPoint(\BitWasp\Buffertools\Buffer::hex($utxo, 32), 0);
  
  
     $transaction = \BitWasp\Bitcoin\Transaction\TransactionFactory::build()
         -&gt;spendOutPoint($outpoint)
         -&gt;payToAddress($utxoAmount - $fee, $addressCreator-&gt;fromString($reciverPublicKey, $networkObject) )
         -&gt;get();
  
     echo "Unsigned transaction: " . $transaction-&gt;getHex() . '&lt;BR&gt;&lt;BR&gt;';
  
     $signScript = \BitWasp\Bitcoin\Script\ScriptFactory::scriptPubKey()-&gt;payToPubKeyHash($keyPairInput-&gt;getPublicKey()-&gt;getPubKeyHash());
     $txOut = new \BitWasp\Bitcoin\Transaction\TransactionOutput($utxoAmount  - $fee, $signScript);
  
     $signer = new \BitWasp\Bitcoin\Transaction\Factory\Signer($transaction);
  
     $signatureChecker = \Btccom\BitcoinCash\Transaction\Factory\Checker\CheckerCreator::fromEcAdapter( \BitWasp\Bitcoin\Bitcoin::getEcAdapter() ); // for version 0.0.35
     $signer-&gt;setCheckerCreator( $signatureChecker ); // for version 0.0.35
     $input = $signer-&gt;input(0, $txOut);
     $signatureType = \Btccom\BitcoinCash\Transaction\SignatureHash\SigHash::ALL | \Btccom\BitcoinCash\Transaction\SignatureHash\SigHash::BITCOINCASH;
     $input-&gt;sign($keyPairInput, $signatureType);
     $signed = $signer-&gt;get();
  
  
     echo "Witness serialized transaction: " . $signed-&gt;getHex() . '&lt;BR&gt;&lt;BR&gt;';
     echo "Base serialized transaction: " . $signed-&gt;getBaseSerialization()-&gt;getHex() . '&lt;BR&gt;&lt;BR&gt;';
     echo "Script validation result: " . ($input-&gt;verify() ? "yes\n" : "no\n"). '&lt;BR&gt;&lt;BR&gt;';
  
     die();
  </code></pre>
  
  <p>In this case I get the result:</p>
  
  <pre><code>Script validation result: no
  </code></pre>
  
  <p>Trying to <a href="https://blockdozer.com/tx/send" rel="nofollow noreferrer">broadcast the BCH transaction</a> gives an error:</p>
  
  <pre><code>An error occured:
  16: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation). Code:-26
  </code></pre>
  
  <p>I think, it means, that signature is wrong. If we remove the flag <code>$signatureType</code> (keep this default), then <code>Script validation result</code> will be <code>yes</code>,  but broadcasting will give an error:</p>
  
  <pre><code>16: mandatory-script-verify-flag-failed (Signature must use SIGHASH_FORKID). Code:-26
  </code></pre>
  
  <p>I think, it means - transaction signed as in bitcoin network, must to be signed by bitcoin-cash rules. Maybe I'm wrong. But bitcoin transaction signing is fine. Bitwasp has no manuals, how to sign a bitcoin-cash transactions, I have the same code for bitwasp v.0.0.34.2 (without addon "btccom/bitwasp-bitcoin-bch-addon", using <code>$signer-&gt;redeemBitcoinCash(true);</code> function) but it gives the same result.</p>
  
  <p>It is interesting that in code of bitcoin-cash signer it takes the inner variable <code>amount</code> and include it in hash:</p>
  
  <pre><code>$hasher = new V1Hasher($this-&gt;transaction, $this-&gt;amount);
  </code></pre>
  
  <p>But for bitcoin bitwasp doesn't take the amount, presumably it takes an amount from the transaction.</p>
  
  <p>Help me please to sign the transaction, bitwasp has only bitcoin examples, not bitcoin-cash. It is very difficult to find any informaion about php altcoins signing without third-party software. Regards.</p>