IOTA TypeScript SDK Quick Start
The IOTA TypeScript SDK is a modular library of tools for interacting with the IOTA blockchain. Use it to send queries to RPC nodes, build and sign transactions, and interact with a IOTA or local network.
Installation
- npm
- Yarn
- pnpm
npm i @iota/iota-sdk
yarn add @iota/iota-sdk
pnpm add @iota/iota-sdk
Network locations
At the moment, you can only use the Alphanet API, faucet and explorer:
- JSON RPC URL:
https://api.iota-rebased-alphanet.iota.cafe:443
- Faucet URL:
https://faucet.iota-rebased-alphanet.iota.cafe/gas
- Explorer: https://explorer.iota.cafe/?network=alphanet
The following table lists the locations for IOTA networks.
Network | Full node | faucet |
---|---|---|
local | http://127.0.0.1:9000 (default) | http://127.0.0.1:9123/gas (default) |
Devnet | https://fullnode.devnet.iota.io:443 | https://faucet.iota-rebased-alphanet.iota.cafe/gas |
Testnet | - | - |
Mainnet | - | - |
Use dedicated nodes/shared services rather than public endpoints for production apps. The public
endpoints maintained by the IOTA Foundation (fullnode.<NETWORK>.iota.io:443
) are rate-limited, and support
only 100 requests per 30 seconds or so. Do not use public endpoints in production applications with
high traffic volume.
You can either run your own Full nodes, or outsource this to a professional infrastructure provider (preferred for apps that have high traffic). You can find a list of reliable RPC endpoint providers for IOTA on the IOTA Dev Portal using the Node Service tab.
Migrate to version 0.38.0
The IOTA TypeScript SDK was refactored beginning with version 0.38.0. If you are updating from an earlier version of the SDK, there are some changes you should consider when updating your code.
Module structure
The IOTA TypeScript SDK is now divided into modular components. Before version 0.38.0, you imported the complete SDK module. Now, you upload the individual packages of the SDK module instead. See the Module Packages section for the list of packages.
Deprecated classes
The IOTA TypeScript SDK deprecates the following classes with version 0.38.0:
JsonRpcProvider
- TheJsonRpcProvider
class is deprecated in favor of theiotaClient
class when creating a client for a IOTA network. See Network Interactions with IOTAClient for more information.SignerWithProver
andRawSigner
- Key pairs now directly support signing transactions and messages without the need of aSigner
class. See the Key pairs topic for more information.signAndExecuteTransactionBlock
- This method was not deprecated, but is now part ofIotaClient
.Connection
classes - TheConnection
classes (Connection
,devnetConnection
, and so on) have been deprecated in favor of usingiotaClient
for establishing the connection. See Network Interactions with IotaClient for more information.- The
superstruct
type definitions forJsonRPCProvider
types are replaced with generated types exported from@iota/iota-sdk/client
. The new type definitions are pure TypeScript types that you can't use for runtime validation. - A more stable JSON-RPC API has reduced the need for many of the SDK "getter" methods, which are now deprecated.
Signing transaction blocks
Signing and sending transaction blocks changes slightly with the deprecation of the Signer
pattern. For an example of transaction signing, see the
IOTA Programmable Transaction Blocks Basics topic.
Faucet requests
The ability to request IOTA from a faucet is not part of IotaClient
as it was with
JsonRpcProvider
. Instead, you must use the requestIotaFromFaucetV0
method from
@iota/iota-sdk/faucet
. The @iota/iota-sdk/faucet
import also provides a getFaucetHost
method
to retrieve the faucet URL for localnet
, testnet
, or devnet
networks.
import { getFaucetHost, requestIotaFromFaucetV0 } from '@iota/iota-sdk/faucet';
await requestIotaFromFaucetV0({
host: getFaucetHost('devnet'),
recipient: '<IOTA_ADDRESS>',
});
Module packages
The SDK contains a set of modular packages that you can use independently or together. Import just what you need to keep your code light and compact.
@iota/iota-sdk/client
- A client for interacting with IOTA RPC nodes.@iota/iota-sdk/bcs
- A BCS builder with pre-defined types for IOTA.@iota/iota-sdk/transaction
- Utilities for building and interacting with transactions.@iota/iota-sdk/keypairs/*
- Modular exports for specific KeyPair implementations.@iota/iota-sdk/verify
- Methods for verifying transactions and messages.@iota/iota-sdk/cryptography
- Shared types and classes for cryptography.@iota/iota-sdk/multisig
- Utilities for working with multisig signatures.@iota/iota-sdk/utils
- Utilities for formatting and parsing various IOTA types.@iota/iota-sdk/faucet
- Methods for requesting IOTA from a faucet.