bitcoin-php: Error: Missing inputs
Hello.
I have installed bitcoin core in regtest mode and i’m connecting via RPC Client. I’m trying to push the signed transaction but i get “Missing inputs” error.
My code:
$addressCreator = new AddressCreator();
$transactionBuilder = TransactionFactory::build();
$privKeyFactory = new PrivateKeyFactory();
$bitcoin = new BaseBitcoin();
$bitcoin->setNetwork(NetworkFactory::bitcoinRegtest()); // Regtest
$privateKey = $privKeyFactory->fromWif($sourceAddressKey, $bitcoin->getNetwork());
$txOuts = [];
// Adding inputs
foreach ($txInputs as $txInput) {
$transactionBuilder->input($txInput['hash'], $txInput['idx']);
array_push($txOuts, new TransactionOutput(
$txInput['value'],
ScriptFactory::fromHex($txInput['script'])
));
}
// Adding destination address
$transactionBuilder->payToAddress(
$spendAmount,
$addressCreator->fromString($destAddreess)
);
// Adding own address for receive change
$transactionBuilder->payToAddress(
$changeAmount,
$addressCreator->fromString($sourceAddress)
);
$transaction = $transactionBuilder->get();
$signer = new Signer($transaction);
$signed = null;
// Signing
foreach ($txOuts as $key => $txOut) {
$signer->sign($key, $privateKey, $txOut);
}
$signed = $signer->get();
return $signed->getHex();
Result example:
- Balance: 200000000 (Satoshi)
- Spend amount: 100000000 (Satoshi)
- Fee amount: 3616 (Satoshi)
- change amount: 99996384 (Satoshi)
Also you can see In this particular example that the fee is 3616 but as you can see in “fees: 0” in transaction.
Decoded raw transaction:
{
"addresses": [
"mzBYfxBuuuPxzW5fmGKX9hhkBCs256NhVL",
"mmPfjQMdFG82pjZmb4VH5WamNefPsAhGer"
],
"block_height": -1,
"block_index": -1,
"confirmations": 0,
"double_spend": false,
"fees": 0,
"hash": "28937e3f382c58274ebd4af1450104e74171d981a1a6a9fab5f518ec3c3d360f",
"inputs": [
{
"age": 0,
"output_index": 1,
"prev_hash": "8e04e0a940344e300d5800cf918a84d234e501d85bf91738f4426108ffcbd3fc",
"script": "473044022065218756d5f4c0f77cdcb6ed27f087cec67acd8d8b21a2fc23c9f5982f1397f2022053e8e30a4f6e321c5809ee3b48329e32c1bb0088cc9604b028341a0b42a469f9014104efde4c2e41e03f38e74d31b3ab6abb294de28d1c9cf068655a1033d9686a706031eeeaee0ab72c0254901f77d3cf0a47e80da05b57fcb59ee7e0c429b6996def",
"script_type": "empty",
"sequence": 4294967295
}
],
"outputs": [
{
"addresses": [
"mzBYfxBuuuPxzW5fmGKX9hhkBCs256NhVL"
],
"script": "76a914ccbec481242b07d48685367206dea401c390d6e788ac",
"script_type": "pay-to-pubkey-hash",
"value": 100000000
},
{
"addresses": [
"mmPfjQMdFG82pjZmb4VH5WamNefPsAhGer"
],
"script": "76a9144070045522f66b038a0ac7cdcd4fe42c6191024e88ac",
"script_type": "pay-to-pubkey-hash",
"value": 99996384
}
],
"preference": "low",
"received": "2020-04-07T15:53:37.066069908Z",
"relayed_by": "18.234.50.70",
"size": 257,
"total": 199996384,
"ver": 1,
"vin_sz": 1,
"vout_sz": 2
}
So, what’s the problem, my code or bitcoin core?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (7 by maintainers)
I got the problem… I have assigned to tx_big_endian_hash the hash of previous transaction. Now works okey. Thank @afk11 for your time.