# Quick start

## Installing the library

The following instructions assume you have a project already created, and you have `npm` installed and operable.

```bash
$ npm install idena-js
```

## Import the library in your project

```typescript
import { Idena, LocalKeyStore } from "idena-js";
```

## Configuration

```typescript
import { Idena, LocalKeyStore } from "idena-js";

const provider = new LocalKeyStore();
const idena = new Idena(provider);
```

## Example

### Create random address and import

This will import your private key in memory letting `idena` object to sign transaction using such key.

```typescript
const provider = new LocalKeyStore();
const idena = new Idena(provider);
```

### Import private key

This will import your private key in memory letting `idena` object to sign transaction using such key.

```typescript
const privateKey = "6a666fb86f57ca37c333768982047781a4a2c31a902a89ee8c2b5bc7e12da444";
const provider = new LocalKeyStore(privateKey);
const idena = new Idena(provider);
```

### Transfer

The `transfer` operation requires an `idena` object with an imported key having some funds.

```typescript
const to = "0xab5801a7d398351b8be11c439e05c5b3259aec9b";
const amount = 0.001;
const operation = await idena.transfer({ amount, to });
console.log(`Hash: ${operation.hash}`);
```

### Wait for transaction mining

When a transaction is injected an `Operation` object is returned. You can use the `confirmation` method to wait for an operation confirmation.

```typescript
const to = "0xab5801a7d398351b8be11c439e05c5b3259aec9b";
const amount = 0.001;
const operation = await idena.transfer({ amount, to });
await operation.confirmation();
console.log(`Hash: ${operation.hash}`);
```

### Bulk transactions&#x20;

You can also send more transactions in bulk.

```typescript
let operations = await idena.bulkTransactions([
    { amount: 6.12, to: "0xab5801a7d398351b8be11c439e05c5b3259aec9b" },
    { amount: 2.12, to: "0xf8db1ee1be12b28aa12477fc66b296dccfa66609" },
    { amount: 4.93, to: "0xbe314949e2b9d14c27fa6785323f7cfc9250f92a" }
]);
operations = await Promise.all(operations.map(op => op.confirmation()));
operations.forEach(op => console.log(`Hash: ${op.hash}`));
```

### Balance

Following example shows how to retrieve balance and stake (where stake are the balance plus the frozen DNA due staking/mining activity).

```typescript
const address = "0xcf979f9472e38d45c577394747a3028ea7433bb5";
const { balance, stake } = await idena.getBalanceByAddress(address);
console.log(balance, stake);
```

### Identity

This method returns an [Identity](https://github.com/idena-dev/idena-js/blob/master/src/models/Identity.ts) object about identity address.&#x20;

```typescript
const address = "0xcf979f9472e38d45c577394747a3028ea7433bb5";
const identity = await idena.getIdentityByAddress(address);
console.log(identity);
```

### Retrieve address

```typescript
const address = await idena.getProvider().getAddress();
```

### Retrieve current epoch

```typescript
const epoch = await idena.getProvider().getEpoch();
```


---

# 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://idena.gitbook.io/idelse/idena-js/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.
