# Light client

Running a full node is the most trustless, private, decentralized and censorship resistant way to interact with Electroneum. It is also the best choice for the health of the network, because a decentralized network relies on having many individual nodes that independently verify the head of the chain. In a full node a copy of the blockchain is stored locally enabling users to verify incoming data against a local source of truth. However, running a full node requires a lot of disk space and non-negligible CPU allocation and takes hours (for snap sync) or days (for full sync) to sync the blockchain from genesis. Etn-sc also offers a light mode that overcomes these issues and provides some of the benefits of running a node but requires only a fraction of the resources.

## Light node vs full node <a href="#light-node-vs-full-node" id="light-node-vs-full-node"></a>

Running Etn-sc in light mode has the following advantages for users:

* Syncing takes minutes rather than hours/days
* Light mode uses significantly less storage
* Light mode is lighter on CPU and other resources
* Light mode is suitable for resource-constrained devices
* Light mode can catch up much quicker after having been offline for a while

However, the cost of this performance increase is that a light Etn-sc node depends heavily on full-node peers that choose, for altruistic reasons, to run light servers. There is no monetary incentive for full nodes to run light servers and it is an opt-in, rather than opt-out function of a Etn-sc full node. For those reasons light servers are rather rare and can quickly become overwhelmed by data requests from light clients. The result of this is that **Etn-sc nodes run in light mode often struggle to find peers**.

A light client can be used to query data from Electroneum and submit transactions, acting as a locally-hosted Electroneum wallet. However they have different security guarantees than full nodes. Because they don't keep local copies of the Electroneum state, light nodes can't validate the blocks in the same way as the full nodes. Instead they fetch block headers by requesting them from full nodes.

### Running a light server <a href="#running-light-server" id="running-light-server"></a>

Full node operators that choose to enable light serving altruistically enable other users to run light clients. This is good for Electroneum because it makes it easier for a wider population of users to interact with Electroneum. However, there is naturally a limit to how much resource a node operator is able and willing to dedicate to serving light clients. Therefore, the command that enables light serving requires arguments that define the upper bound on resource allocation. The value given is in percent of a processing thread, for example `--light.serve 300` enables light-serving and dedicates three processing threads to it.

Etn-sc unindex older transactions to save disk space. Indexing is required for looking up transactions in Etn-sc's database. Therefore, unindexing limits the data that can be requested by light clients. This unindexing can be disabled by adding `--tx.txlookuplimit 0` to make the maximum data available to light clients.

The whole command for starting Etn-sc with a light server could look as follows:

```sh
./etn-sc --light.serve 50 --txlookuplimit 0
```

### Running a light client <a href="#running-light-client" id="running-light-client"></a>

Running a light client simply requires Etn-sc to be started in light mode. It is likely that a user would also want to interact with the light node using, for example, RPC. This can be enabled using the `--http` command.

```sh
./etn-sc --syncmode light --http --http.api "eth,debug"
```

Data can be requested from this light Etn-sc instance in the same way as for a full node (i.e. using the [JSON-RPC-API](/electroneum-stack/electroneum-client-apis/json-rpc.md) using tools such as [Curl](https://curl.se/) or Etn-sc's [Javascript console](/etn-sc-client/interacting-with-etn-sc/js-console.md)). Instead of fetching the data from a local database as in a full node, the light Etn-sc instance requests the data from full-node peers.

It's also possible to send transactions. However, light clients are not connected directly to Electroneum Mainnet but to a network of light servers that connect to Electroneum Mainnet. This means a transaction submitted by a light client is received first by a light server that then propagates it to full-node peers on the light-client's behalf. This reliance on honest light-servers is one of the trust compromises that comes along with running a light node instead of a full node.

### Summary <a href="#summary" id="summary"></a>

Running a full node is the most trustless way to interact with Electroneum. However, Etn-sc provides a low-resource "light" mode that can be run on modest computers and requires much less disk space. The trade-offs are additional trust assumptions and a small pool of light-serving peers to connect to.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.electroneum.com/etn-sc-client/fundamentals/light-client.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
