<p>You can use <a href="https://github.com/litecoin-project/litecore-explorers" rel="nofollow noreferrer">https://github.com/litecoin-project/litecore-explorers</a> like this:</p>

<pre><code>var explorers = require('bitcore-explorers');
var insight = new explorers.Insight(https://insight.litecore.io', 'mainnet');

insight.getUtxos('mgBmKKZEkK...', function(err, utxos) {
  if (err) {
    // Handle errors...
  } else {
    // Do something with utxos
  }
});
</code></pre>

CC BY-SA 4.0
2018-06-05T19:45:41.337Z
2018-06-05T19:45:41.337Z
Michael Rodriguez
<p>Here is the module what you may require
<a href="https://www.npmjs.com/package/litecore-explorers" rel="nofollow noreferrer">https://www.npmjs.com/package/litecore-explorers</a></p>

CC BY-SA 4.0
2018-05-24T07:29:52.937Z
This package is the result of my attempts to adopt `bitcore-explorers` package for litecoin, so it doesn't work! Don't try to use it!
Dmytro Zarezenko
CC BY-SA 3.0
2017-11-13T02:43:57.677Z
2017-11-13T02:43:57.677Z
Jin Zhen
<p>I used the <code>request</code> library to manually retrieve information from the insight API. I also used the <code>litecore-lib</code> library to create the transaction.</p>

<pre><code>var Litecoin = require("litecore-lib");
var request = require("request");

//manually hit an insight api to retrieve utxos of address
function getUTXOs(address) {
  return new Promise((resolve, reject) =&gt; {
    request({
      uri: 'https://insight.litecore.io/api/addr/' + address + '/utxo',
      json: true
    },
      (error, response, body) =&gt; {
        if(error) reject(error);
        resolve(body)
      }
    )
  })
}

//manually hit an insight api to broadcast your tx
function broadcastTX(rawtx) {
  return new Promise((resolve, reject) =&gt; {
    request({
      uri: 'https://insight.litecore.io/tx/send',
      method: 'POST',
      json: {
        rawtx
      }
    },
      (error, response, body) =&gt; {
        if(error) reject(error);
        resolve(body.txid)
      }
    )
  })
}

//your private key and address here
var privateKey = PrivateKey.fromWIF('YOUR_PRIVATE_KEY_HERE');
var address = privateKey.toPublicKey().toAddress();

getUTXOs(address)
  .then((utxos) =&gt; {

    let balance = 0;
    for (var i = 0; i &lt; utxos.length; i++) {
      balance +=utxos[i]['satoshis'];
    } //add up the balance in satoshi format from all utxos

    var fee = 1500; //fee for the tx
    var tx = new Litecoin.Transaction() //use litecore-lib to create a transaction
      .from(utxos)
      .to('TO_ADDRESS', balance - fee) //note: you are sending all your balance AKA sweeping
      .fee(fee)
      .sign(privateKey)
      .serialize();

    return broadcastTX(tx) //broadcast the serialized tx
  })
  .then((result) =&gt; {
    console.log(result) // txid
  })
  .catch((error) =&gt; {
    throw error;
  })
</code></pre>

<p>Cheers!</p>

CC BY-SA 3.0
2017-12-19T17:53:51.073Z
2017-12-19T17:53:51.073Z
Monstrum
<p>I have coded <code>NodeJS</code> script for <code>bitcoin</code> for send all balance from by address to some other one. Now I want to do this for the <code>litecoin</code>. For <code>bitcoin</code> I have used <a href="https://github.com/bitpay/bitcore-lib" rel="nofollow noreferrer">bitcore-lib</a> and <a href="https://github.com/bitpay/bitcore-explorers" rel="nofollow noreferrer">bitcore-explorers</a> libs to do that.</p>

<p>For <code>litecoin</code> I have found forked and adopted lib <a href="https://github.com/litecoin-project/litecore-lib/" rel="nofollow noreferrer">litecore-lib</a>, but I can't found solution to receive <code>UTXO</code> data for some LTC address like I do it in case of <code>bitcoin</code>:</p>

<pre><code>var Insight = require("bitcore-explorers").Insight;
var insight = new Insight(network);
insight.getUnspentUtxos(sourceAddress, function (error, utxos) {
    // determine balance, fee and sign transaction
}
</code></pre>

<p>How can I do this for <code>litecoin</code>? Thanks!</p>

<transactions><litecoin><utxo><bitcore><node.js>
Litecoin litecore-lib receive UTXO and current balance
Dmytro Zarezenko
# Litecoin litecore-lib receive UTXO and current balance

(Asked by: username_0 on 2017-10-24)

I have coded `NodeJS` script for `bitcoin` for send all balance from by address to some other one. Now I want to do this for the `litecoin`. For `bitcoin` I have used [bitcore-lib](https://github.com/bitpay/bitcore-lib) and [bitcore-explorers](https://github.com/bitpay/bitcore-explorers) libs to do that.

For `litecoin` I have found forked and adopted lib [litecore-lib](https://github.com/litecoin-project/litecore-lib/), but I can't found solution to receive `UTXO` data for some LTC address like I do it in case of `bitcoin`:

```
var Insight = require("bitcore-explorers").Insight;
var insight = new Insight(network);
insight.getUnspentUtxos(sourceAddress, function (error, utxos) {
    // determine balance, fee and sign transaction
}

```

How can I do this for `litecoin`? Thanks!

**Tags:** transactions, litecoin, utxo, bitcore, node.js


---

## 3 answers

### Answer by username_3 on 2017-12-19. Score: 4 | Accepted answer

I used the `request` library to manually retrieve information from the insight API. I also used the `litecore-lib` library to create the transaction.

```
var Litecoin = require("litecore-lib");
var request = require("request");

//manually hit an insight api to retrieve utxos of address
function getUTXOs(address) {
  return new Promise((resolve, reject) => {
    request({
      uri: 'https://insight.litecore.io/api/addr/' + address + '/utxo',
      json: true
    },
      (error, response, body) => {
        if(error) reject(error);
        resolve(body)
      }
    )
  })
}

//manually hit an insight api to broadcast your tx
function broadcastTX(rawtx) {
  return new Promise((resolve, reject) => {
    request({
      uri: 'https://insight.litecore.io/tx/send',
      method: 'POST',
      json: {
        rawtx
      }
    },
      (error, response, body) => {
        if(error) reject(error);
        resolve(body.txid)
      }
    )
  })
}

//your private key and address here
var privateKey = PrivateKey.fromWIF('YOUR_PRIVATE_KEY_HERE');
var address = privateKey.toPublicKey().toAddress();

getUTXOs(address)
  .then((utxos) => {

    let balance = 0;
    for (var i = 0; i < utxos.length; i++) {
      balance +=utxos[i]['satoshis'];
    } //add up the balance in satoshi format from all utxos

    var fee = 1500; //fee for the tx
    var tx = new Litecoin.Transaction() //use litecore-lib to create a transaction
      .from(utxos)
      .to('TO_ADDRESS', balance - fee) //note: you are sending all your balance AKA sweeping
      .fee(fee)
      .sign(privateKey)
      .serialize();

    return broadcastTX(tx) //broadcast the serialized tx
  })
  .then((result) => {
    console.log(result) // txid
  })
  .catch((error) => {
    throw error;
  })

```

Cheers!


---

### Answer by username_1 on 2018-06-05. Score: 0

You can use <https://github.com/litecoin-project/litecore-explorers> like this:

```
var explorers = require('bitcore-explorers');
var insight = new explorers.Insight(https://insight.litecore.io', 'mainnet');

insight.getUtxos('mgBmKKZEkK...', function(err, utxos) {
  if (err) {
    // Handle errors...
  } else {
    // Do something with utxos
  }
});

```


---

### Answer by username_2 on 2017-11-13. Score: -2

Here is the module what you may require
<https://www.npmjs.com/package/litecore-explorers>

> **Comments:**
> **username_0**: This package is the result of my attempts to adopt `bitcore-explorers` package for litecoin, so it doesn't work! Don't try to use it!  

---

