Skip to main content

Getting Started with Wasm

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.

Before You Start

The IOTA SDK library also offers dedicated Node.js bindings. The differences with this package are outlined below:

Wasm bindingsNode.js bindings
EnvironmentNode.js, browsersNode.js
Installation-Rust, Cargo required*
Performance✔️✔️✔️
Ledger Nano✔️
Rocksdb✔️
Stronghold✔️
  • The Node.js bindings only need to be compiled during npm install if a pre-compiled binary is not available for your platform.
tl;dr:

Use the Node.js bindings if you can. The Wasm bindings are just more portable and support browser environments.

Requirements

  • One of the following Node.js versions: '16.x', '18.x';
  • wasm-bindgen. You can install it by running:
cargo install wasm-bindgen-cli

Install Using a Package Manager

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

npm i @iota/sdk-wasm

Web Setup

Unlike Node.js, a few more steps are required to use this binding in a browser.

The library loads the compiled Wasm file with an HTTP GET request, so the iota_sdk_wasm_bg.wasm file must be copied to the root of the distribution folder.

A bundler such as webpack or rollup is recommended.

  1. Install rollup-plugin-copy:

    npm install rollup-plugin-copy --save-dev
  2. Add the plugin to your rollup.config.js:

    // Include the copy plugin.
    import copy from 'rollup-plugin-copy';

    // ...

    // Add the copy plugin to the `plugins` array:
    copy({
    targets: [
    {
    src: 'node_modules/@iota/sdk-wasm/web/wasm/iota_sdk_wasm_bg.wasm',
    dest: 'public',
    rename: 'iota_sdk_wasm_bg.wasm',
    },
    ],
    });

Usage

Client

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

The following example creates a Client instance connected to the Shimmer Testnet, and retrieves the node's information by calling Client.getInfo(), and then print the node's information.

bindings/wasm/README.md
loading...

Wallet

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

The following example will create a new Wallet Account that connects to the Shimmer Testnet using the MnemonicSecretManager by calling the Wallet.createAccount(data) function.

bindings/wasm/README.md
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 Node.js 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

API Reference

If you are using the Wasm binding, you use the Node.js API reference in the IOTA Wiki.