Sign rawtransaction does not work: Transaction has unexpected data
A2DNEW opened this issue · 2 comments
A2DNEW commented
I want to sign raw transaction
1- i created key and address with function:
const keyPair = ECPair.makeRandom({ network: dogecoin });
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey, network: dogecoin });
console.log('address', address); // DEnbFjV4kmEiUfrmY27seaLY9kW5r7YtZV
console.log('keyPair', keyPair.toWIF()); // QVTvEg3fkC5qYdkNRCB7TffWG3NBDzJvNEEpXhPendKL8Q3Y1FcN
2- i use createrawtransaction:
('createrawtransaction', [
[
{
"txid": "2a44f088778bee025f9c016880daac779be9f2e917f4363cb0dbe756514d6f18", // generate random
"vout": 1
}
],
{
"DEnbFjV4kmEiUfrmY27seaLY9kW5r7YtZV": 1,
}
])
and result is:
0100000001186f4d5156e7dbb03c36f417e9f2e99b77acda8068019c5f02ee8b7788f0442a0100000000ffffffff0100e1f505000000001976a91469d07e272841c62bd02cc261dc820189bbf12da788ac00000000
3- i want to sign the transaction:
const alice = ECPair.fromWIF(
'QVTvEg3fkC5qYdkNRCB7TffWG3NBDzJvNEEpXhPendKL8Q3Y1FcN',
dogecoin,
);
const psbt = new bitcoin.Psbt({ network: dogecoin });
psbt.addInput({
hash: '2a44f088778bee025f9c016880daac779be9f2e917f4363cb0dbe756514d6f18',
index: 0,
nonWitnessUtxo: Buffer.from(
'0100000001186f4d5156e7dbb03c36f417e9f2e99b77acda8068019c5f02ee8b7788f0442a0100000000ffffffff0100e1f505000000001976a91469d07e272841c62bd02cc261dc820189bbf12da788ac00000000',
'hex',
),
});
psbt.addOutput({
address: 'DPZSrvbCvBiAVAX6GpSBw8patJ7K6NaFa4',
value: 1,
});
and i get error: Non-witness UTXO hash for input #0 doesn't match the hash specified in the prevout
how can i sign the transaction?
thank you
junderw commented
Change index from 0 to 1. ( "vout": 1
)
A2DNEW commented
Change index from 0 to 1. (
"vout": 1
)
I changed it:
{
"txid": "2a44f088778bee025f9c016880daac779be9f2e917f4363cb0dbe756514d6f18",
"vout": 1
}
But i get error again:
Non-witness UTXO hash for input #0 doesn't match the hash specified in the prevout
for this line: psbt.signInput(0, alice);