I’m making an attempt to make use of the rpc command listunspent
to get all of the UTXOs related to an tackle, after which I’m making an attempt to move it to a transaction, utilizing bitcore-lib.
Beneath is my code:
const Shopper = require('bitcoin-core');
const bitcore = require('bitcore-lib');
const consumer = new Shopper({
community: 'regtest',
username: 'bitcoinuser',
password: 'bitcoinpass',
port: 18443
});
var tx = new bitcore.Transaction();
var sourceAddress = ["mwkT2k1o6k4dF7ZZQ2VBbw7VedBkQA2CBK"];
var minconf = 6;
var maxconf = 999999;
var targetAddress = "2Mw3iwZdVXjeb7BN5hWqegFs8VdfZo5Rmdo";
var privateKey = "cQqVxdtPz95monJe8QJUE4h5JVtSSAjTQ1SU6z8PL9pmFj5V7ieA";
var txns = [];
consumer.listUnspent(minconf, maxconf, sourceAddress)
.then(perform(assist){
txns = assist.slice();
return txns;
}).then(perform(txns){
return tx.from(txns).to(targetAddress, 15000).signal(privateKey);
}).then(perform(consequence){
console.log(consequence);
});
The result’s much like the transaction object.
What I would like is to obtain the transaction hash, which I can then broadcast.
Be aware: I’m making an attempt to run my core in regtest mode, I don’t need to use livenet or testnet. I’ve additionally disclosed the private and non-private keys, as they don’t maintain any actual worth.
The primary few traces of the output appears like this:
Transaction {
inputs:
[ PublicKeyInput {
witnesses: [],
output:
Output {
_satoshisBN:
BN { unfavorable: 0, phrases: [ 16972032, 37 ], size: 2, crimson: null
},
_satoshis: 2500000000,
_scriptBuffer:
<Buffer 21 02 0b 0f c0 79 9d 39 8d 83 be 39 08 2c 72 49 0a 57 00 0e c2 f5 e0 01 ab a1 ee 9b 07 19 cc bd fb e3 ac>,
_script:
Script {
chunks:
[ { buf:
<Buffer 02 0b 0f c0 79 9d 39 8d 83 be 39 08 2c 72 49 0a 57 00 0e c2 f5 e0 01 ab a1 ee 9b 07 19 cc bd fb e3>,
len: 33,
opcodenum: 33 },
{ opcodenum: 172 } ],
_isOutput: true } },
prevTxId:
<Buffer e1 45 8a fb cd df 9b 8b aa 4c a7 a0 13 b7 f6 d3 91 87 8f a3 02 94 78 92 ef 59 03 0e 40 f5 51 00>,
outputIndex: 0,
sequenceNumber: 4294967295,
_script: Script { chunks: [], _isInput: true },
_scriptBuffer: <Buffer > },
PublicKeyInput {
witnesses: [],
output:
Output {
_satoshisBN: