# Quick start

### Install

Byteball.js was designed to work both in the browser and in Node.js.

#### Node.js

To install Byteball.js on Node.js, open your terminal and run:

```
npm i byteball --save
```

#### Browser

You can create an index.html file and include Byteball.js with:

```markup
<script src="https://cdn.jsdelivr.net/npm/byteball"></script>
```

### Usage

Ways to initiate WebSocket client:

```javascript
const byteball = require('byteball');

// Connect to mainnet official node 'wss://byteball.org/bb'
const client = new byteball.Client();

// Connect to a custom node
const client = new byteball.Client('wss://byteball.org/bb');

// Connect to testnet
const options = { testnet: true };
const client = new byteball.Client('wss://byteball.org/bb-test', options);
```

Close the client:

```javascript
client.close();
```

All API methods follow this pattern:

```javascript
// If the last argument is a function it is treated as a callback
client.api.getJoint('oj8yEksX9Ubq7lLc+p6F2uyHUuynugeVq4+ikT67X6E=', function(err, result) {
  console.log(err, result);
});

// If a callback is not provided, a Promise is returned
client.api.getJoint('oj8yEksX9Ubq7lLc+p6F2uyHUuynugeVq4+ikT67X6E=').then(function(result) {
  console.log(result);
});
```

### Transaction

To compose and post unit you need first to create a Byteball wallet and fund it with the native currency ‘bytes’. The generated WIF will be used on Byteball.js. Click on the link below to learn more:

{% content-ref url="/pages/-LJU1DogFsLlfL3PS6\_L" %}
[Generate a random address](/0.1.2/utils/generate-wallet.md)
{% endcontent-ref %}

Sending a payment:

```javascript
const wif = '5JBFvTeSY5...'; // WIF string generated (private key)

const params = {
  outputs: [
    {
      address: 'NX2BTV43XN6BOTCYZUUFU6TK7DVOC4LU', // The Byteball address of the recipient
      amount: 1000 // The amount he receives
    }
  ]
};

client.post.payment(params, wif, function(err, result) {
  console.log(result); // The unit hash is returned
});
```


---

# 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://obytejs.com/0.1.2/getting-started/quick-start.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.
