Tuesday, June 2, 2026
HomeBitcoinjson rpc - The way to correctly use the rpc command `listunspent`...

json rpc – The way to correctly use the rpc command `listunspent` with `bitcore-lib` to create a transaction and get the transaction hash?

I’m making an attempt to make use of the rpc command listunspent to get all of the UTXOs related to an handle, after which I’m making an attempt to go it to a transaction, utilizing bitcore-lib.
Under is my code:

const Consumer = require('bitcoin-core');
const bitcore = require('bitcore-lib');
const consumer = new Consumer({ 
  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(outcome){
    console.log(outcome);
  });

The result’s much like the transaction object.

What I need is to obtain the transaction hash, which I can then broadcast.

Notice: 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 seems like this:

Transaction {
  inputs:
   [ PublicKeyInput {
       witnesses: [],
       output:
        Output {
          _satoshisBN:
           BN { damaging: 0, phrases: [ 16972032, 37 ], size: 2, crimson: null 
},
          _satoshis: 2500000000,
          _scriptBuffer:
           ,
          _script:
           Script {
             chunks:
              [ { buf:
                   ,
                  len: 33,
                  opcodenum: 33 },
                { opcodenum: 172 } ],
             _isOutput: true } },
       prevTxId:
        ,
       outputIndex: 0,
       sequenceNumber: 4294967295,
       _script: Script { chunks: [], _isInput: true },
       _scriptBuffer:  },
     PublicKeyInput {
       witnesses: [],
       output:
        Output {
          _satoshisBN:

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments