# @iota/sdk-wasm

> WebAssembly bindings for the IOTA SDK library

Latest version **1.1.3** (published 2024-01-29) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @iota/sdk-wasm
pnpm add @iota/sdk-wasm
yarn add @iota/sdk-wasm
bun add @iota/sdk-wasm
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; large bundle.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2024-01-29 |
| First published | 2023-07-07 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=16 |
| Dependencies | 6 |
| Unpacked size | 13.8 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 61 |
| Author | IOTA Foundation |
| Maintainers | tuditi, msarcevic, braniota, lmoe, domschiener, lexerr, martyniota, nothingismagick, laumair, iota_ci, rubenkoch, brord |

## Links

- npm: https://www.npmjs.com/package/@iota/sdk-wasm
- Repository: https://github.com/iotaledger/iota-sdk
- Homepage: https://github.com/iotaledger/iota-sdk#readme
- Issues: https://github.com/iotaledger/iota-sdk/issues
- npm.io page: https://npm.io/package/@iota/sdk-wasm

## Dependencies (6)

- [qs](https://npm.io/package/qs.md) ^6.9.7
- [semver](https://npm.io/package/semver.md) ^7.5.2
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.7
- [text-encoding](https://npm.io/package/text-encoding.md) ^0.7.0
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [class-transformer](https://npm.io/package/class-transformer.md) ^0.5.1

## Recent versions

- 1.1.3 (latest) — 2024-01-29
- 3.0.0-beta.1 (next) — 2026-09-02
- 2.0.0-beta.1 (alpha) — 2024-05-08
- 3.0.0-alpha.1 — 2026-06-16
- 2.0.0-alpha.3 — 2024-04-19
- 2.0.0-alpha.2 — 2024-04-02
- 2.0.0-alpha.1 — 2024-03-26
- 1.1.2 — 2023-12-07
- 1.1.1 — 2023-10-16
- 1.1.0 — 2023-09-29
- 1.0.6 — 2023-09-14
- 1.0.5 — 2023-08-18
- 1.0.4 — 2023-08-01
- 1.0.3 — 2023-07-31
- 1.0.2 — 2023-07-28
- … 4 more at https://npm.io/package/@iota/sdk-wasm/versions

## README

# IOTA SDK Library - WebAssembly Bindings

WebAssembly (Wasm) bindings for TypeScript/JavaScript to the IOTA SDK library.

## Which Bindings to Choose?

The IOTA SDK library also offers dedicated [Node.js bindings](../nodejs). The differences with this package are outlined
below.

**NOTE: Use the Node.js bindings if you can. The Wasm bindings are more portable and exist to support browser
environments.**

|              |   Wasm bindings   |   Node.js bindings    |
|:-------------|:-----------------:|:---------------------:|
| Environment  | Node.js, browsers |        Node.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.

## Requirements

- One of the following Node.js versions: '16.x', '18.x';
- `wasm-bindgen` (`cargo install wasm-bindgen-cli`);

## Getting Started

### Installing Using a Package Manager

To install the library from your package manager of choice, you only need to run the following:

#### npm

```bash
npm i @iota/sdk-wasm
```

#### yarn

```bash
yarn add @iota/sdk-wasm
```

### Web Setup

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](https://webpack.js.org/) or [rollup](https://rollupjs.org/) is recommended.

### Rollup

1. Install `rollup-plugin-copy`:

    ```bash
    npm install rollup-plugin-copy --save-dev
    ```

2. Add the plugin to your `rollup.config.js`:

    ```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'
      }]
    })
    ```

### Webpack

1. Install `copy-webpack-plugin`:

    ```bash
    npm install copy-webpack-plugin --save-dev
    ```

2. Add the plugin to your `webpack.config.js`:

    ```js
    // Include the copy plugin.
    const CopyWebPlugin = require('copy-webpack-plugin');
    
    // ...
    
    experiments: {
        // futureDefaults: true, // includes asyncWebAssembly, topLevelAwait etc.
        asyncWebAssembly: true
    }
    
    // Add the copy plugin to the `plugins` array:
    plugins: [
        new CopyWebPlugin({
          patterns: [
            {
              from: 'node_modules/@iota/sdk-wasm/web/wasm/iota_sdk_wasm_bg.wasm',
              to: 'iota_sdk_wasm_bg.wasm'
            }
          ]
        }),
        // other plugins...
    ]
    ```

## Client Usage

The following example creates a [`Client`](https://wiki.iota.org/shimmer/iota-sdk/references/nodejs/classes/Client/)
instance connected to
the [Shimmer Testnet](https://api.testnet.shimmer.network), and retrieves the node's information by
calling [`Client.getInfo()`](https://wiki.iota.org/shimmer/iota-sdk/references/nodejs/classes/Client/#getinfo),
and then print the node's information.

### Node.js

```javascript
const {Client, initLogger} = require('@iota/sdk-wasm/node');

async function run() {
    initLogger();

    const client = new Client({
        nodes: ['https://api.testnet.shimmer.network'],
        localPow: true,
    });

    try {
        const nodeInfo = await client.getInfo();
        console.log('Node info: ', nodeInfo);
    } catch (error) {
        console.error('Error: ', error);
    }
}

run().then(() => process.exit());
```

### Web

```javascript
import init, {Client, initLogger} from "@iota/sdk-wasm/web";

init().then(async () => {
    initLogger();

    const client = new Client({
        nodes: ['https://api.testnet.shimmer.network'],
        localPow: true,
    });

    const nodeInfo = await client.getInfo();
    console.log('Node info: ', nodeInfo);
}).catch(console.error);

// Default path to load is "iota_sdk_wasm_bg.wasm", 
// but you can override it by passing a path explicitly.
//
// init("./static/iota_sdk_wasm_bg.wasm").then(...)
```

## Wallet Usage

The following example will create a
new [`Wallet`](https://wiki.iota.org/iota-sdk/references/nodejs/classes/Wallet/) [`Account`](https://wiki.iota.org/iota-sdk/references/nodejs/classes/Account/)
that connects to the [Shimmer Testnet](https://api.testnet.shimmer.network) using the
[`MnemonicSecretManager`](https://wiki.iota.org/iota-sdk/references/nodejs/interfaces/MnemonicSecretManager/)
by calling
the [`Wallet.createAccount(data)`](https://wiki.iota.org/iota-sdk/references/nodejs/classes/Wallet/#createaccount)
function.

### Node.js

```javascript
const { Wallet, CoinType } = require('@iota/sdk-wasm/node');

async function run() {
    try {
        const wallet = new Wallet({
            storagePath: './my-database',
            coinType: CoinType.Shimmer,
            clientOptions: {
                nodes: ['https://api.testnet.shimmer.network'],
            },
            secretManager: {
                mnemonic: "my development mnemonic",
            },
        });

        const account = await wallet.createAccount({
            alias: 'Alice',
        });

        const addresses = await account.addresses();
        console.log(addresses);
    } catch (err) { console.error }
}

run().then(() => process.exit());
```

### Web

```javascript
import init, {Wallet, CoinType} from "@iota/sdk-wasm/web";

init().then(async () => {
    const wallet = new Wallet({
        storagePath: './my-database',
        coinType: CoinType.Shimmer,
        clientOptions: {
            nodes: ['https://api.testnet.shimmer.network'],
        },
        secretManager: {
            mnemonic: "my development mnemonic",
        },
    });

    const account = await wallet.createAccount({
        alias: 'Alice',
    });

    const addresses = await account.addresses();
    console.log(addresses);
}).catch(console.error);

// Default path to load is "iota_sdk_wasm_bg.wasm", 
// but you can override it by passing a path explicitly.
//
// init("./static/iota_sdk_wasm_bg.wasm").then(...)
```

## API Reference

If you are using the Wasm binding, you use the Node.js API reference in the
[IOTA Wiki](https://wiki.iota.org/shimmer/iota-sdk/references/nodejs/api_ref/).

---
_Source: https://npm.io/package/@iota/sdk-wasm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
