Quick start

Installing the library

The following instructions assume you have a project already created, and you have npm installed and operable.
1
$ npm install idena-js
Copied!

Import the library in your project

1
import { Idena, LocalKeyStore } from "idena-js";
Copied!

Configuration

1
import { Idena, LocalKeyStore } from "idena-js";
2
3
const provider = new LocalKeyStore();
4
const idena = new Idena(provider);
Copied!

Example

Create random address and import

This will import your private key in memory letting idena object to sign transaction using such key.
1
const provider = new LocalKeyStore();
2
const idena = new Idena(provider);
Copied!

Import private key

This will import your private key in memory letting idena object to sign transaction using such key.
1
const privateKey = "6a666fb86f57ca37c333768982047781a4a2c31a902a89ee8c2b5bc7e12da444";
2
const provider = new LocalKeyStore(privateKey);
3
const idena = new Idena(provider);
Copied!

Transfer

The transfer operation requires an idena object with an imported key having some funds.
1
const to = "0xab5801a7d398351b8be11c439e05c5b3259aec9b";
2
const amount = 0.001;
3
const operation = await idena.transfer({ amount, to });
4
console.log(`Hash: ${operation.hash}`);
Copied!

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.
1
const to = "0xab5801a7d398351b8be11c439e05c5b3259aec9b";
2
const amount = 0.001;
3
const operation = await idena.transfer({ amount, to });
4
await operation.confirmation();
5
console.log(`Hash: ${operation.hash}`);
Copied!

Bulk transactions

You can also send more transactions in bulk.
1
let operations = await idena.bulkTransactions([
2
{ amount: 6.12, to: "0xab5801a7d398351b8be11c439e05c5b3259aec9b" },
3
{ amount: 2.12, to: "0xf8db1ee1be12b28aa12477fc66b296dccfa66609" },
4
{ amount: 4.93, to: "0xbe314949e2b9d14c27fa6785323f7cfc9250f92a" }
5
]);
6
operations = await Promise.all(operations.map(op => op.confirmation()));
7
operations.forEach(op => console.log(`Hash: ${op.hash}`));
Copied!

Balance

Following example shows how to retrieve balance and stake (where stake are the balance plus the frozen DNA due staking/mining activity).
1
const address = "0xcf979f9472e38d45c577394747a3028ea7433bb5";
2
const { balance, stake } = await idena.getBalanceByAddress(address);
3
console.log(balance, stake);
Copied!

Identity

This method returns an Identity object about identity address.
1
const address = "0xcf979f9472e38d45c577394747a3028ea7433bb5";
2
const identity = await idena.getIdentityByAddress(address);
3
console.log(identity);
Copied!

Retrieve address

1
const address = await idena.getProvider().getAddress();
Copied!

Retrieve current epoch

1
const epoch = await idena.getProvider().getEpoch();
Copied!