Skip to main content

Getting Started With iota.js

Iota.rs

Though this library is functionally complete, the iota.rs library is maintained by more contributors, more performant and has the latest features.

Required Prior Knowledge

This wiki assumes that you already know the basics of TypeScript. If you are unfamiliar with the language, you can find documentation to get started in the official TypeScript documentation.

If you have never programmed in your life, MIT has published an open introductory course to programming which could help you get started.

Prerequisites

Before you can start using the library, you will need to install the following software:

  • node: You should use v15, or above.
  • npm: You should use v7, or above.

Install the Library

You can install the iota.js library using npm with a single command:

npm install @iota/[email protected]

Use the Library

Once you have installed the library, you can start using it by requiring the iota.js package as shown in the following example which connects to a Chrysalis node and logs some of its properties to the console.

const {SingleNodeClient} = require("@iota/iota.js");

async function run() {
const client = new SingleNodeClient("https://chrysalis-nodes.iota.org");

const info = await client.info();
console.log("Node Info");
console.log("\tName:", info.name);
console.log("\tVersion:", info.version);
console.log("\tIs Healthy:", info.isHealthy);
console.log("\tNetwork Id:", info.networkId);
console.log("\tLatest Milestone Index:", info.latestMilestoneIndex);
console.log("\tConfirmed Milestone Index:", info.confirmedMilestoneIndex);
console.log("\tPruning Index:", info.pruningIndex);
console.log("\tFeatures:", info.features);
console.log("\tMin PoW Score:", info.minPowScore);
}

run()
.then(() => console.log("Done"))
.catch((err) => console.error(err));

How-To Guides

You can find additional usage examples in the How To section.