Spend multiple UTXO on a single transaction #TESTNET


(Grog) #1

How to build a proper transaction with multiple UTXO ?

I’m currently playing with Transaction Playground (very cool btw) and I’m against something I don’t understand.

I want to spend the only utxo related to these address

  • mwYyUSbseegdJb6kkeA73QwRTVjkwLL8PL
  • mrwa2VsbmkbeqTiLP9GCkqpdL6QxufLJLN
  • mwhzFewFiPCqf1YUAAcNXNmPMKVuVpnaDF

I use the fetch utxo feature, select them, then add an appropriate output.
After that, I sign with three different private key.

At this point, I can compare two things that should be similar :

  • The result of Transaction under the hood when serialized
  • Serialized transaction

But both raw transaction are not the same (I use decode_tx to do so).

I broadcast the Serialized transaction and It works as expected (transaction), great, but to achieve the same result I expected to “copy past” what it is show on under the hood.

Then I tried things but I didn’t achieve something working.

Under the hood

var transaction = new bitcore.Transaction()
.from({"address":"mwhzFewFiPCqf1YUAAcNXNmPMKVuVpnaDF","txid":"f0d8f7b5523cf70b1c74c773394187392adae4f41504876fe9118ca5ee3f909a","vout":1,"scriptPubKey":"76a914b198391d84379ae6770026dd26350e40cea9ca2f88ac","amount":0.56})
.to('mfYy1JhqrUCKuBNVFcFLURzG5L7uqocTkZ', 77459100)
.sign('privKey1')
.sign('privKey2')
.sign('privKey3')

Where are the other input ? :confused:

My last try

var utxos = [];
utxos.push(new bitcore.Transaction.UnspentOutput({
"address":"mwYyUSbseegdJb6kkeA73QwRTVjkwLL8PL",
"txid":"77e889343ab2f39645a8060d1feca7e5300419c38b1aa231f96fbac1f03e6942",
"vout":0,
"scriptPubKey":"76a914b198391d84379ae6770026dd26350e40cea9ca2f88ac",
"amount":0.12}));
utxos.push(new bitcore.Transaction.UnspentOutput({
"address":"mrwa2VsbmkbeqTiLP9GCkqpdL6QxufLJLN",
"txid":"c1e85f5c6aa863309cd428556859f2288f01ef81fdfe37cb6cd61cbe17850ca0",
"vout":0,
"scriptPubKey":"76a914b198391d84379ae6770026dd26350e40cea9ca2f88ac",
"amount":0.095}));
utxos.push(new bitcore.Transaction.UnspentOutput({
"address":"mwhzFewFiPCqf1YUAAcNXNmPMKVuVpnaDF",
"txid":"f0d8f7b5523cf70b1c74c773394187392adae4f41504876fe9118ca5ee3f909a",
"vout":1,
"scriptPubKey":"76a914b198391d84379ae6770026dd26350e40cea9ca2f88ac",
"amount":0.56}));

var transaction = new bitcore.Transaction()
.from(utxos)
.to('mfYy1JhqrUCKuBNVFcFLURzG5L7uqocTkZ', 77459100)
.sign('21ed473b07768398ba8eaec1a5011dcc06e3114de07b69f7a28a8b7b70b17f7b')
.sign('31277c7d975f907b0179807d5ec4057e77f3807a413b26d5822a9a4ead8aa206')
.sign('ed0d964315f2679eaccc09bea2a150c2b647252e4c4d017e6c7d47340feb7a7d');

Well, obviously It can’t work now given that I already consume these inputs but still, I tried to broadcast the result raw transaction before and it didn’t work :confused:


(Grog) #2

Well, instead of pushing all the UnspentOutput object into an array and give it to .from(array) method, just use as many .from as you inputs you have and it works but still, I don’t get it why it didn’t work as I did :confused: