Friday, November 22, 2024

signature – Error with signed bitcoin transaction PHP 7.2.34

Kindly assist with this problem.

I’m making an attempt to create a bitcoin transaction however preserve getting:-
Error: non-mandatory-script-verify-flag (Script failed an OP_EQUALVERIFY operation) .

I consider I am utilizing the proper keys.

My signed transaction hex is:
010000000001012e1d32ebc3fa508fc740c6b589b32787e7c16132093e49008386ab59118c76f00000000000ffffffff028089000000000000160014facb445a65e273a1475b46f279a6d2bcbacf87c59a420000000000001600142865223582201a799e229c19a15ef4d7ec72097202483045022100ab0d9a9e02a8bc5907d49e4e21edbabd2a47e0eabdd97506f364bd7d9b443bd202205586775ac5ceec73a5d226c11e4076a7ca8b96a432408cc885c14af65b047ce901210353825959e0f36eff9a1257fa07ad919406a9bba4d100c6df601bc44c63d0ab1100000000

Under is my code:
$privateKey = (new BitWaspBitcoinKeyFactoryPrivateKeyFactory)->fromWif(‘XXXXXXXXXXXXXXXXXXXXXXXXXX’);

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

$satoshi = 100000000; //one bitcoin in satoshi ie 100 million
$send_wallet_amount = 0.0005425 * $satoshi;
$ship = 0.0003520 * $satoshi; // satoshis
$payment = 0.00002 * $satoshi; // satoshis
//calculate change
$change = $send_wallet_amount – $ship – $payment;

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

$transaction = TransactionFactory::construct()
->enter(‘f0768c1159ab868300493e093261c1e78727b389b5c640c78f50fac3eb321d2e’, 0 )
//->spendOutPoint($outpoint)
//handle to ship to
->payToAddress($ship, (new BitWaspBitcoinAddressAddressCreator)->fromString(‘bc1qlt95gkn9ufe6z36mgme8nfkjhjavlp79ynjrdz’))
//change
->payToAddress($change, (new BitWaspBitcoinAddressAddressCreator)->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 => $enter) {
//$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 as $idx => $transactionOutput) {
$signer->signal($idx, $privateKey, $transactionOutput, $signData);
}
$signedTx = $signer->get();
$hex = $signedTx->getHex();

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles