bitcoinjs/bitcoinjs-lib

Sign rawtransaction does not work: Non-witness UTXO hash for input #0 doesn't match the hash specified in the prevout

A2DNEW opened this issue · 2 comments

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: 1,
  nonWitnessUtxo: Buffer.from(
    '0100000001186f4d5156e7dbb03c36f417e9f2e99b77acda8068019c5f02ee8b7788f0442a0100000000ffffffff0100e1f505000000001976a91469d07e272841c62bd02cc261dc820189bbf12da788ac00000000', // use from createrawtransaction
    'hex',
  ),
});

psbt.addOutput({
  address: 'DPZSrvbCvBiAVAX6GpSBw8patJ7K6NaFa4',
  value: 1,
});

psbt.signInput(0, alice); // i get error here

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

The content of nonWitnessUtxo must be the fully signed transaction at 2a44f088778bee025f9c016880daac779be9f2e917f4363cb0dbe756514d6f18 that funds the input.

You are not giving the correct transaction.

createrawtransaction doesn't put out a PSBT, so you can't sign it using PSBT. You can only sign it using your dogecoin client.

The content of nonWitnessUtxo must be the fully signed transaction at 2a44f088778bee025f9c016880daac779be9f2e917f4363cb0dbe756514d6f18 that funds the input.

You are not giving the correct transaction.

createrawtransaction doesn't put out a PSBT, so you can't sign it using PSBT. You can only sign it using your dogecoin client.

Thank you
is there any document for it?