Skip to main content

Getting Started with Node.js

Safe Password Storage

In a production setup, do not store passwords in the host's environment variables or in the source code. See our backup and security recommendations for production setups.

Requirements

  • One of the following Node.js versions: '16.x', '18.x';

Install the IOTA SDK

Install Using a Package Manager

To start using the IOTA SDK in your Node.js project, you can install the IOTA SDK from your package manager of choice:

npm i @iota/sdk

Build the Binding from Source

Requirements

If you want to build the IOTA SDK from source, please ensure you have the installed the following:

Windows

On Windows, you will also need LLVM. Our workflow uses https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.1/LLVM-11.0.1-win64.exe. You may also need to set an environment variable RUSTFLAGS to -C target-feature=+crt-static.

Install LLVM with Chocolatey

If you use Chocolatey you can install LLVM by executing choco install llvm

Build

You can build the IOTA SDK from source by doing the following:

  1. Download the repository to any directory you choose:
git clone https://github.com/iotaledger/iota-sdk
  1. Move to the Node.js binding directory:
cd iota-sdk/bindings/nodejs
  1. Install the necessary dependencies with either of the following commands:
npm install
  1. Build the SDK:
npm run build

This command uses the cargo-cp-artifact utility to run the Rust build and copy the built library into ./build/Release/index.node. Prebuild requires that the binary is in build/Release as though it was built with node-gyp.

Usage

Client

After you installed the library, you can create a Client instance and interface with it.

bindings/nodejs/examples/client/getting-started.ts
loading...

Wallet

After you installed the library, you can create a Wallet instance and interact with it.

bindings/nodejs/examples/wallet/getting-started.ts
loading...

What's next?

How-To Guides

Once you have installed the IOTA SDK, you can start building your application. You can find usage examples in this Wiki's how-to guides.

More Examples

You can use the provided code examples to get acquainted with the IOTA SDK. You can use the following commands to run any example:

cd examples
yarn
yarn run-example ./[example folder]/[example file]
  • Where [example file] is the file name from the example folder. For example:
yarn run-example  examples/client/00_get_info.ts