Getting Started with Kotlin
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 Kotlin bindings allow JVM developers to interact with the IOTA network. These bindings use JNI (Java Native Interface) to bridge the performance of the Rust core SDK with the ease of use of Kotlin and Java.
Prerequisites
Before using the Kotlin bindings, ensure you have:
- JDK: Version 11 or higher (JDK 17 recommended).
- Build Tool: Gradle or Maven.
- Architecture: The SDK currently supports x86_64 and ARM64 (macOS/Linux).
Installation
- Pre-built (Recommended)
- Build from Source
Gradle
Add the IOTA SDK dependency to your build.gradle.kts file:
loading...
Maven
Add the following to your pom.xml:
<dependency>
<groupId>org.iota</groupId>
<artifactId>iota-sdk</artifactId>
<version>0.0.1-alpha.4</version>
</dependency>
Since the Kotlin SDK wraps a Rust binary, the native library must be present in your library path. On some systems, you may need to specify the path manually when running your application:
java -Djava.library.path=/path/to/native/library -jar your-app.jar
The Kotlin bindings include prebuilt native libraries for most platforms (Windows, macOS, Linux). In most cases, adding the dependency via Gradle or Maven will download a compatible binary.
If a prebuilt binary is not available for your platform or architecture, you can build the SDK from source. A Rust toolchain is required to compile the native Rust library.
A typical workflow is:
# Clone the SDK repository
git clone https://github.com/iotaledger/iota-rust-sdk.git
# Navigate to the Kotlin bindings folder
cd iota-rust-sdk/bindings/kotlin
# Build the native library and install it locally (Gradle example)
./gradlew build
Once built, ensure your native library path points to the compiled Rust library so that the Kotlin SDK can load it.
For more details on development setup, platform-specific notes, and linking, refer to the Kotlin bindings README in the repository.
Quick Start Example
The following example demonstrates how to initialize a client and retrieve the Chain ID using Kotlin.
1. Create a Main.kt
Create a new file and paste the following code:
loading...
2. Run the code
If using Gradle, run:
./gradlew run
What's Next?
Now that you have connected to the network, you can explore:
- Wallet API: Manage high-level accounts and automated address syncing.
- Secret Manager: Securely handle Mnemonic, Stronghold, or Ledger hardware wallets.
- Output Builders: Create complex transaction outputs (NFTs, Alias, etc.).
View more comprehensive examples in the official Kotlin examples directory.