# JavaScript

{% hint style="success" %}
Visit the [project on GitHub](https://github.com/ltonetwork/lto-api.js).
{% endhint %}

## Installation

```
npm install @ltonetwork/api --save
```

## Usage

```javascript
import LTO from '@ltonetwork/lto';
import { Transfer } from '@ltonetwork/transactions';
import { Event } from '@ltonetwork/events';
import { Message } from '@ltonetwork/messages';

// Account
const lto = new LTO('T'); // 'T' for testnet, 'L' for mainnet
const account = lto.account();

// Public layer
const amount = 1000;
const recipient = "3JmEPiCpfL4p5WswT21ZpWKND5apPs2hTMB";

const transaction = new Transfer(recipient, amount).signWith(account);
await lto.node.broadcast(transaction);

// Private layer
const chain = new EventChain(account);

const body = {
  '@context': 'instantiate_msg.json',
  ownable_id: '88pDRu52FpsU3kKHwdvPV21RMkBqVqNnthjfdCesTHQhLnUpanw49n6b2PzGnEy',
  package: 'bafybeie4ts4mbcw4pswzh45bj32ulcyztup2dr7zbbjv3y2ym3q3uuejba',
  network_id: 'T',
};

new Event(body).addTo(chain).signWith(account);

const message = new Message(chain).to(recipient).signWith(account);
await lto.anchor(message.hash);
await lto.relay.send(message);
```

## Testnet

To obtain testnet tokens, please join the [@ltotech Telegram group](https://docs.ltonetwork.com/libraries/broken-reference) and ask for testnet tokens. Testnet tokens will be provided to you by the community for free.


---

# 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://docs.ltonetwork.com/libraries/javascript.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.
