Getting Started with WASM/TypeScript
The IOTA SDK is currently in alpha. APIs, interfaces, and behavior may change without notice between releases. It is not yet recommended for production use.
The IOTA SDK WASM bindings allow JavaScript and TypeScript developers to use the SDK in Node.js and the browser. The core Rust SDK is compiled to WebAssembly, and the package ships with a TypeScript API and type declarations.
If you are building a web dApp, also consider the IOTA TypeScript SDK, a native TypeScript implementation with React tooling (dApp Kit). The WASM bindings expose the same API surface as the other IOTA SDK bindings, which makes them a good fit if you want identical behavior across languages.
Prerequisites
Before using the WASM bindings, ensure you have:
- Node.js: Version 20 or higher (for Node.js usage), or a browser with WebAssembly support.
Installation
- Pre-built (Recommended)
- Build from Source
Add the IOTA SDK to your project using your package manager:
npm install @iota/[email protected]
The package contains the compiled WebAssembly binary and TypeScript declarations, so no Rust toolchain is required.
To build the WASM bindings locally, you need a Rust toolchain with the wasm32-unknown-unknown target, the wasm-bindgen CLI, and pnpm:
git clone https://github.com/iotaledger/iota-rust-sdk.git
cd iota-rust-sdk
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli --version 0.2.122
make wasm
The output is written to bindings/wasm/dist/. For additional setup instructions, refer to the WASM bindings README in the repository.
Quick Start Example
The following example demonstrates how to connect to the IOTA Testnet and retrieve the Chain ID.
1. Create a chain_id.mjs file
Create a new file named chain_id.mjs and paste the following code. The WASM module must be initialized with initAsync() before any other call:
loading...
2. Run the code
In your terminal, run:
node chain_id.mjs
Usage in the Browser
The same API works in the browser. See the browser example for a complete HTML page that loads the WASM module and queries the chain ID.
What's Next?
Now that you have connected to the network, you can explore more advanced features:
- Accounts and Addresses: create a mnemonic, derive addresses, and check coin balances.
- Transactions: build, sign, and send Programmable Transaction Blocks (PTBs), including staking and reusing command results.
- Queries: query owned objects, events, and transactions with the GraphQL client.
View more comprehensive examples in the official WASM examples directory.