From d30ee491f5b353801fd33d1d028bfa454bb10818 Mon Sep 17 00:00:00 2001 From: junderw Date: Tue, 7 Jan 2020 15:55:40 +0900 Subject: [PATCH] Update README to use PSBT --- README.md | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b1128c8..2a39dd7 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,16 @@ let utxos = [ txId: '...', vout: 0, ..., - value: 10000 + value: 10000, + // For use with PSBT: + // not needed for coinSelect, but will be passed on to inputs later + nonWitnessUtxo: Buffer.from('...full raw hex of txId tx...', 'hex'), + // OR + // if your utxo is a segwit output, you can use witnessUtxo instead + witnessUtxo: { + script: Buffer.from('... scriptPubkey hex...', 'hex'), + value: 10000 // 0.0001 BTC and is the exact same as the value above + } } ] let targets = [ @@ -56,9 +65,17 @@ console.log(fee) // .inputs and .outputs will be undefined if no solution was found if (!inputs || !outputs) return -let txb = new bitcoin.TransactionBuilder() +let psbt = new bitcoin.Psbt() -inputs.forEach(input => txb.addInput(input.txId, input.vout)) +inputs.forEach(input => + psbt.addInput({ + hash: input.txId, + index: input.vout, + nonWitnessUtxo: input.nonWitnessUtxo, + // OR (not both) + witnessUtxo: input.witnessUtxo, + }) +) outputs.forEach(output => { // watch out, outputs may have been added that you need to provide // an output address/script for @@ -67,7 +84,10 @@ outputs.forEach(output => { wallet.nextChangeAddress() } - txb.addOutput(output.address, output.value) + psbt.addOutput({ + address: output.address, + value: output.value, + }) }) ```