Quick start

Installing the library

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

$ npm install idena-js

Import the library in your project

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

Configuration

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.

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.

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.

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.

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

Bulk transactions

You can also send more transactions in bulk.

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).

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

Identity

This method returns an Identity object about identity address.

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

Retrieve address

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

Retrieve current epoch

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

Last updated