Bitcoin

Signature – Signed Bitcoin transaction error PHP 7.2.34

Please kindly help me with this issue.

I’m trying to create a Bitcoin transaction, but I keep getting an error:- Error: non-mandatory-script-verify-flag (Script failed an OP_EQUALVERIFY Operation) .

I think I’m using the correct key.

Here is my signed transaction hexadecimal number: 010000000001012e1d32ebc3fa508fc740c6b589b32787e7c16132093e49008386ab59118c76f00000000000ffffffff028089000000000000160014facb4 45a65 e273a1475b46f279a6d2bcbacf87c59a420000000000001600142865223582201a799e229c19a15ef4d7ec72097202483045022100ab0d9a9e02a8bc5907d49 e4e 21edbabd2a47e0eabdd97506f364bd7d9b443bd202205586775ac5ceec73a5d226c11e4076a7ca8b96a432408cc885c14af65b047ce901210353825959e0f36eff9a1257 fa0 7ad919406a9bba4d100c6df601bc44c63d0ab1100000000

Here is my code: $privateKey = (new BitWasp\Bitcoin\Key\Factory\PrivateKeyFactory)->fromWif(‘XXXXXXXXXXXXXXXXXXXXXXXXXXXX’);

// Utxo is: outpoint.txid, outpoint.vout, txout.scriptPubKey, txout.amount $outpoint = new OutPoint(Buffer::hex(‘f0768c1159ab868300493e093261c1e78727b389b5c640c78f50fac3eb321d2e’), 0); $outputScript = ScriptFactory::scriptPubKey()->payToPubKeyHash($privateKey->getPubKeyHash());

$Satoshi = 100000000; //1 Satoshi’s Bitcoin, i.e. 100 million $send_wallet_amount = 0.0005425 * $satoshi; $send = 0.0003520 * $satoshi; // Satoshi $fee = 0.00002 * $satoshi; // satoshis //Calculate changes $change = $send_wallet_amount – $send – $fee;

$txOut = new TransactionOutput($send_wallet_amount, $outputScript);

$transaction = TransactionFactory::build() ->input(‘f0768c1159ab868300493e093261c1e78727b389b5c640c78f50fac3eb321d2e’, 0 ) //->spendOutPoint($outpoint) //Send address ->payToAddress($send, (new BitWasp\Bit ) Coin\Address\AddressCreator )->fromString(‘bc1qlt95gkn9ufe6z36mgme8nfkjhjavlp79ynjrdz’)) //change ->payToAddress($change, (new BitWasp\Bitcoin\Address\AddressCreator)->fromString(‘bc1q9pjjydvzyqd8n83znsv6zhh56lk8yztj3m7cjn ‘)) – >get();

$tx_hex = $transaction->getHex();

$redeemScript = ScriptFactory::scriptPubKey()->p2wkh($privateKey->getPubKeyHash());

$p2shScript = new P2shScript($redeemScript); $signData = new SignData(); $signData->p2sh($redeemScript);

$transactionOutputs = (); foreach ($transaction->getInputs() as $idx => $input) //$transactionOutput = new TransactionOutput(0, ScriptFactory::fromHex($input->getScript()->getBuffer()->getHex() ))); $transactionOutput = new TransactionOutput(0, ScriptFactory::fromHex($p2shScript->getBuffer()->getHex())); array_push($transactionOutputs, $transactionOutput);

$signer = new Signer($transaction, Bitcoin::getEcAdapter()); foreach ($transactionOutputs with $idx => $transactionOutput) $signer->sign($idx, $privateKey, $transactionOutput, $signData);

$signedTx = $signer->get();

Related Articles

Back to top button