Singing a RAW transaction utilizing bitcoin-php

on

|

views

and

comments


I’ve a unsigned transaction hex. Now I need to signal this transaction enter with my personal key in PHP utilizing the BitWasp Library. I’ve adopted among the examples and searched the boards and can’t get my head round it.

I get the uncooked transaction from the https://counterparty.io/docs/api/

I get the error Invalid script Signature – Should be push solely.

My Uncooked Unsigned TX:

010000000147e4efecb198d013f9a938904d560d4c831cb3e7ae84cf899c10c5689ed0c2ed000000001976a91409c4d51c89d31a374706ae80249bb408f02b86ba88acffffffff0200000000000000002a6a2846e58e6bfb7a15bc6cd36b7e545f4c86b49ea57539d2b77b57a822a3ac811d7d6846e3416cccc4c673600000000000001976a91409c4d51c89d31a374706ae80249bb408f02b86ba88ac00000000

My code :

    <?php

require_once __DIR__ . "/vendor/autoload.php";

use BitWaspBitcoinScriptScriptFactory;
use BitWaspBitcoinTransactionOutPoint;
use BitWaspBitcoinUtxoUtxo;
use BitWaspBuffertoolsBuffer;
use BitWaspBitcoinTransactionTransactionOutput;
use BitWaspBitcoinAddressAddressCreator;
use BitWaspBitcoinAddressPayToPubKeyHashAddress;
use BitWaspBitcoinBitcoin;
use BitWaspBitcoinKeyFactoryPrivateKeyFactory;
use BitWaspBitcoinNetworkNetworkFactory;
use BitWaspBitcoinTransactionFactorySigner;
use BitWaspBitcoinTransactionTransactionFactory;

Bitcoin::setNetwork(NetworkFactory::bitcoin());
$community = Bitcoin::getNetwork();
$ecAdapter = Bitcoin::getEcAdapter();

$addrCreator = new AddressCreator();
$privFactory = new PrivateKeyFactory($ecAdapter);

$priv = $privFactory->fromWif('MY-PRIVATE-KEY');


$txHex = '010000000147e4efecb198d013f9a938904d560d4c831cb3e7ae84cf899c10c5689ed0c2ed000000001976a91409c4d51c89d31a374706ae80249bb408f02b86ba88acffffffff0200000000000000002a6a2846e58e6bfb7a15bc6cd36b7e545f4c86b49ea57539d2b77b57a822a3ac811d7d6846e3416cccc4c673600000000000001976a91409c4d51c89d31a374706ae80249bb408f02b86ba88ac00000000';
$myTx = TransactionFactory::fromHex($txHex);

$transactionOutputs = [];
foreach ($myTx->getInputs() as $idx => $enter) {
    $transactionOutput = new TransactionOutput(0, ScriptFactory::fromHex($input->getScript()->getBuffer()->getHex()));
    array_push($transactionOutputs, $transactionOutput);
}


$signer = new Signer($myTx, $ecAdapter);

foreach ($transactionOutputs as $idx => $transactionOutput) {
    $signer->signal($idx, $priv, $transactionOutput);
}

$signed = $signer->get();
echo $signed->getHex() . PHP_EOL;

Please can somebody clarify what it’s im doing fallacious and clarify it in layman phrases?

Share this
Tags

Must-read

Waymo raises $16bn to gas international robotaxi enlargement | Know-how

Self-driving automobile firm Waymo on Monday stated it raised $16bn in a funding spherical that valued the Alphabet subsidiary at $126bn.Waymo co-chief executives...

Self-driving taxis are coming to London – ought to we be anxious? | Jack Stilgoe

At the top of the nineteenth century, the world’s main cities had an issue. The streets had been flooded with manure, the unintended...

US regulators open inquiry into Waymo self-driving automobile that struck youngster in California | Expertise

The US’s federal transportation regulator stated Thursday it had opened an investigation after a Waymo self-driving car struck a toddler close to an...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here