question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HowTo: Construct a txID of an unsigned PSBT

See original GitHub issue

Hi,

as the title says, I would like to build the txID of an unsigned PSBT transaction. I built the PSBT with the following code snippet:

const psbt = new bitcoin.Psbt({ network });
psbt.setVersion(1);
for (const input of finalInputs) {
  psbt.addInput({ hash: input.txId, index: input.vout, witnessUtxo: input.WitnessUtxo });
}
finalOutputs.forEach(output => {
   psbt.addOutput({ address: output.address, value: output.value });
});

As I read through some threads here, I saw that it’s possible to get the txID with BuildIncomplete via the TransactionBuilder but I wasn’t able to get it in any way from a PSBT transaction.

I would really appreciate if you could point me into the right direction!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
SiestaMadokaistcommented, Feb 5, 2020

you could get the TransactionBuilder via:

const psbt = new bitcoin.Psbt({ network })
// doing things with psbt.
const tx = psbt.__CACHE.__TX;
// that will give you a bitcoin.Transaction object, if you need the bitcoin.TransactionBuilder then you need to add the following line.
const txb = bitcoin.TransactionBuilder.fromTransaction(tx)

although, the __CACHE is for now still private interface, meaning, it might break in the future update.

I’m not sure if there’s a more appropriate way to do that as of now.

1reaction
junderwcommented, Feb 28, 2020

I was speaking on a theoretical basis.

In terms of your method (unsupported) the reason why this is happening is because PSBT leaves the inputs empty until the tx is extracted.

With P2SH-P2WSH you will need to have a scriptSig (input script) with the redeemscript.

tx.ins[i].script = bitcoinjs.script.compile([redeemScriptBuffer]) should allow you to use the work around for P2SH-P2WSH as well.

However, be careful, as JavaScript passes by reference, so if you add those scripts the scripts will be added to the internal TX of the PSBT as well… so don’t do anything with the PSBT object after you’ve done this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create unsigned tx (PSBT) in a watch-only wallet using bitcoin ...
create wallet. cold-storage-example. Run the below commands in electrum console:
Read more >
6. PSBT transactions - Build your own Bitcoin hardware wallet
Content:- Bitcoin transactions: legacy and segwit- BIP-174 - Partially Signed Bitcoin Transaction format- Parsing and change address ...
Read more >
psbtbumpfee (0.21.0 RPC) - Bitcoin Core
psbtbumpfee "txid" ( options ) Bumps the fee of an opt-in-RBF transaction T, replacing it with a new transaction B. Returns a PSBT...
Read more >
Command to populate PSBT inputs from given UTXOs
utxos must be an array of “txid:vout”, each of which must be reserved or available: the ... psbt (string): Unsigned PSBT which fulfills...
Read more >
BIP 0174 - Bitcoin Wiki
Creating unsigned or partially signed transactions to be passed ... The Partially Signed Bitcoin Transaction (PSBT) format consists of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found