I want to create a Tx with bitcoincashjs: create-a-transaction But how do I specify multi inputs: from(utxo) and multi outputs: to ?
const bch = require('bitcoincashjs');
const privateKey = new bch.PrivateKey('L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy');
const utxos = [{
'txId' : '115e8f72f39fad874cfab0deed11a80f24f967a84079fb56ddf53ea02e308986',
'outputIndex' : 0,
'address' : '17XBj6iFEsf8kzDMGQk5ghZipxX49VXuaV',
'script' : '76a91447862fe165e6121af80d5dde1ecb478ed170565b88ac',
'satoshis' : 50000
}, {
'txId' : '115e8f72f39fad874cfab0deed11a80f24f967a84079fb56ddf53ea02e308986',
'outputIndex' : 0,
'address' : '17XBj6iFEsf8kzDMGQk5ghZipxX49VXuaV',
'script' : '76a91447862fe165e6121af80d5dde1ecb478ed170565b88ac',
'satoshis' : 50000
}];
const transaction = new bch.Transaction()
.from(utxos)
.to('1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK', 15000)
.sign(privateKey);
console.log(transaction.toString())
from
: A high level interface to add an input from a UTXO. It has a series of variants:
from(utxo)
: add an input from an Unspent Transaction Output. Currently, only P2PKH outputs are supported.
from(utxos)
: same as above, but passing in an array of Unspent Outputs.
from(utxo, publicKeys, threshold)
: add an input that spends a UTXO with a P2SH output for a Multisig script. The publicKeys argument is an array of public keys, and threshold is the number of required signatures in the Multisig script.
Details: https://bitcore.io/api/lib/transaction#adding-inputs