# Litecoin

> GetBlock provides RPC endpoints that implement the Litecoin JSON-RPC API standard. These methods are core functionalities for interacting with Litecoin nodes.

The Litecoin network offers a comprehensive suite of methods that enable developers to interact seamlessly with its blockchain infrastructure. This overview provides an in-depth examination of these methods, categorizing them into key functional areas for better understanding and implementation.

What you can expect to find in this documentation

* Compatibility with the Litecoin mainnet and testnets
* Purpose, functionality, and use cases of each Litecoin method
* Required input parameters
* Sample requests and responses
* Code examples in multiple programming languages (Python, JavaScript)

What you can do with this API:

* Query real-time blockchain data
* Retrieve block and transaction information
* Monitor mempool and network status
* Submit and track transactions
* Access mining statistics and difficulty

> **Info:** _**TECHNICAL DISCLAIMER: AUTHORITATIVE JSON-RPC API SPECIFICATION.**_
> 
> _GetBlock's RPC API reference documentation is provided exclusively for informational purposes and streamlined developer experience optimization. The canonical and normative specification for Litecoin JSON-RPC methods is solely maintained and published through the official Litecoin Core documentation._

## Base URL

#### Frankfurt, Germany

```
https://shared.eu-central-1.getblock.io
```

## Supported Networks

| Network | JSON RPC | Blockbook (REST) | Blockbook (WebSocket) |
| --- | --- | --- | --- |
| Mainnet | ✅ | ✅ | ✅ |

> **Info:** JSON-RPC is the Litecoin Core node interface. Blockbook is a separate add-on providing an address- and xpub-indexed view of the chain, and its REST and WebSocket interfaces are provisioned as their own endpoints with their own URLs. A JSON-RPC endpoint does not answer address, UTXO, or wallet queries, and the Litecoin Core wallet RPCs such as `listunspent` are disabled on shared nodes. See the [Blockbook add-on](/add-ons/blockbook/).

| Interface | Use it for |
| --- | --- |
| [JSON-RPC](/api-reference/litecoin/litecoin-json-rpc-api/) | Node-level queries: blocks, raw transactions, mempool, mining, network state |
| [Blockbook REST](/api-reference/litecoin/litecoin-blockbook-rest-api/) | Address balances, UTXOs, wallet-level xpub queries, transaction history, fiat rates |
| [Blockbook WebSocket](/api-reference/litecoin/litecoin-blockbook-websocket-api/) | The same queries plus live subscriptions to new blocks and address activity |

## Quickstart

In this section, you will learn how to make your first call with either:

* Axios
* Python

Before you begin, you must have already installed [`npm`](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) or [`yarn`](https://classic.yarnpkg.com/lang/en/docs/install) on your local machine (for the Axios example) or Python and pip (for the Python example).

#### Javascript(Axios)

### Setup project

Create and initialize a new project:

#### npm

```bash
mkdir litecoin-api-quickstart
cd litecoin-api-quickstart
npm init --yes
```

#### yarn

```bash
mkdir litecoin-api-quickstart
cd litecoin-api-quickstart
yarn init -y
```

### Install Axios

#### npm

```bash
npm install axios
```

#### yarn

```bash
yarn add axios
```

### Create file

Create a new file named `index.js`. This is where you will make your first call.

### Set ES module type

Set the ES module `"type": "module"` in your `package.json`.

### Add code

Add the following code to `index.js`:

#### index.js

```javascript
import axios from "axios";

const url = `https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/`;

const payload = {
  jsonrpc: '2.0',
  id: 1,
  method: 'getblockcount',
  params: []
};

axios.post(url, payload)
  .then(response => {
    console.log('Current block height:', response.data.result);
  })
  .catch(error => {
    console.error(error);
  });
```

Replace `<ACCESS-TOKEN>` with your actual access token from GetBlock.

### Run the script

```bash
node index.js
```

Expected output (example):

```json
{
    "result": 3050080,
    "error": null,
    "id": "getblock.io"
}
```

#### Tab

### Setup the project directory

```bash
mkdir litecoin-api-quickstart
cd litecoin-api-quickstart
```

### Create and activate a virtual environment

```bash
python -m venv venv
source venv/bin/activate

# On Windows, use venv\Scripts\activate
```

### Install requests

```bash
pip install requests
```

### Create script

Create a file called `main.py` with the following content:

#### main.py

```python
import requests

# Replace <ACCESS-TOKEN> with your actual API key from GetBlock
url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"

# Create a JSON-RPC payload
payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getblockcount",
    "params": []
}

headers = {
    "Content-Type": "application/json"
}

try:
    # Send the POST request
    response = requests.post(url, json=payload, headers=headers)
    response.raise_for_status()  # Check for HTTP errors
    data = response.json()

    # Print the result
    print(f"Current block height: {data['result']}")
except requests.exceptions.RequestException as e:
    print(f"An error occurred: {e}")
except KeyError:
    print("Unexpected response format:", response.text)
```

Replace `<ACCESS-TOKEN>` with your actual access token from GetBlock.

### Run the script

```bash
python main.py
```

## Available Methods

Litecoin is documented across three interfaces, each provisioned as its own endpoint.

1. [Litecoin JSON-RPC API](/api-reference/litecoin/litecoin-json-rpc-api/): The Litecoin Core node interface: blocks, raw transactions, mempool inspection, mining data, network state, and fee estimation. Methods are grouped by area on the section page.
1. [Litecoin Blockbook REST API](/api-reference/litecoin/litecoin-blockbook-rest-api/): Address- and xpub-indexed queries over HTTP: balances, transaction history, unspent outputs, wallet-level xpub lookups, balance history, and fiat rates.
1. [Litecoin Blockbook (WebSocket) API](/api-reference/litecoin/litecoin-blockbook-websocket-api/): The same indexed queries over a persistent connection, plus subscriptions to new blocks and to activity on a set of addresses.

> **Info:** A JSON-RPC endpoint has no address index, so address balances and UTXO lookups belong on Blockbook. The Litecoin Core wallet RPCs, including `listunspent`, are disabled on shared nodes because those nodes carry no user wallets.

## Support

For technical support and questions:

* Support: [support@getblock.io](mailto:support@getblock.io)

## See Also

* [Litecoin Developer Documentation](https://litecoin.info/docs)
* [Litecoin Core GitHub](https://github.com/litecoin-project/litecoin)
* [Litecoin Block Explorer (Blockchair)](https://blockchair.com/litecoin)
* [Litecoin Block Explorer (SoChain)](https://sochain.com/LTC)
* [Litecoin Block Explorer (Litecoinspace)](https://litecoinspace.org/)
* [Bitcoin JSON-RPC API](https://developer.bitcoin.org/reference/rpc/)
* [Litecoin Foundation Website](https://litecoin.org/)
* [MWEB Documentation](https://github.com/litecoin-project/lips/blob/master/lip-0002.mediawiki)
