"bitwasp/bitcoin": "^1.0"
我在 GitHub 上找到了一个 PHP 比特币包,它的星数最多。我试图通过 tesnet 将一些比特币从隔离见证地址发送到另一个隔离见证地址,按照示例
https://github.com/Bit-Wasp/bitcoin-php/blob/1.0/examples/tx.fund.p2wpkh.php实际工作
<?php
BitWasp::setNetwork(NetworkFactory::bitcoinTestnet());
$network = BitWasp::getNetwork();
$ecAdapter = BitWasp::getEcAdapter();
$privateKey = 'cNDENaGUxLDUveptKTpap5ntvZEd7aytvyiRRyQaR9nKQ7L2Wdjp';
$txid = '5d16df78dbfa335502124ef85fc8e49ff9414086ef8e80f377c9aeff692152ad';
$to = 'tb1qx92d8azr93janzx4q80rqeujt63tq53v740shj';
$qty = 10400;
$qtyAfterFee = 10000;
// From
$privateKey = (new PrivateKeyFactory())->fromWif($privateKey, $network);
$scriptPubKey = ScriptFactory::scriptPubKey()->payToPubKeyHash($privateKey->getPubKeyHash());
// To
$to = (new AddressCreator())->fromString($to, $network);
// Utxo
$outpoint = new OutPoint(Buffer::hex($txid, 32), 0);
$txOut = new TransactionOutput($qty, $scriptPubKey);
$tx = (new TxBuilder())
->spendOutPoint($outpoint)
->output($qtyAfterFee, $to->getScriptPubKey())
->get();
// Sign transaction
$signed = (new Signer($tx, $ecAdapter))
->sign(0, $privateKey, $txOut)
->get();
$broadcast = $signed->getHex();
// Hex: 0100000001ad522169ffaec977f3808eef864041f99fe4c85ff84e12025533fadb78df165d000000006a47304402207b48f5e1f78d8e3903646abbe2953743625f3aed033ff971bec266f4cabd85d602206da9171e72168a0224e3547950be848a60ce455dd93762d41c6410ac8e12d9a4012102d4206262fda5b9fa3dd124b90166f469e9ef072437582da92c4574a7c2a87241ffffffff0110270000000000001600143154d3f4432c65d988d501de3067925ea2b0522c00000000
$broadcast = $this->sendTx($broadcast);
dd($broadcast);
不幸的是,我在这里遇到了一些错误。
Client error: `POST https://blockstream.info/testnet/api/tx` resulted in a `400 Bad Request` response:
sendrawtransaction RPC error: {"code":-26,"message":"non-mandatory-script-verify-flag (Witness requires empty scriptSig) (truncated...)
我该如何解决这个问题?或者有一个完全可以找到的示例?