Getting Started With Java
It is not recommended to store passwords or seeds on a host's environment variables or in the source code in a production setup. Please follow our backup and security recommendations for production use.
IOTA Wallet Java Library
Get started with the official IOTA Wallet Java library.
Requirements
minimum Java version >= 8
Use in your Android project (Android Studio)
- Download the
iota-wallet-1.0.0-rc.1.jar
file from the GitHub release and add it as a library to your project. - Download the
iota-wallet-1.0.0-rc.1-android.zip
file from the GitHub release, unzip it and add thejniLibs
folder with its contents to your Android Studio project as shown below:
project/
├──src/
└── main/
├── AndroidManifest.xml
├── java/
└── jniLibs/
├── arm64-v8a/ <-- ARM 64bit
│ └── libiota-wallet.so
│ └── libc++_shared.so
├── armeabi-v7a/ <-- ARM 32bit
│ └── libiota-wallet.so
│ └── libc++_shared.so
│── x86/ <-- Intel 32bit
│ └── libiota-wallet.so
│ └── libc++_shared.so
└── x86_64/ <-- Intel 64bit
└── libiota-wallet.so
└── libc++_shared.so
Use in your Java project (Linux, macOS, Windows)
Depending on your operating system, add one of the following dependencies to your build.gradle
file:
linux-x86_64
implementation 'org.iota:iota-wallet:1.0.0-rc.1:linux-x86_64'
windows-x86_64
implementation 'org.iota:iota-wallet:1.0.0-rc.1:windows-x86_64'
aarch64-apple-darwin
implementation 'org.iota:iota-wallet:1.0.0-rc.1:aarch64-apple-darwin'
osx-x86_64
implementation 'org.iota:iota-wallet:1.0.0-rc.1:osx-x86_64'
Use the Library
In order to use the library, you need to create a Wallet
instance.
Note: Android applications must necessarily configure a suitable storage path for the wallet to avoid problems with file system permissions. Specify a suitable storage path as illustrated below:
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
import org.iota.Wallet;
import org.iota.types.AccountHandle;
import org.iota.types.ClientConfig;
import org.iota.types.CoinType;
import org.iota.types.WalletConfig;
import org.iota.types.exceptions.WalletException;
import org.iota.types.secret.StrongholdSecretManager;
public class CreateAccount {
private static final String DEFAULT_DEVELOPMENT_MNEMONIC = "hidden enroll proud copper decide negative orient asset speed work dolphin atom unhappy game cannon scheme glow kid ring core name still twist actor";
public static void main(String[] args) throws WalletException, InitializeWalletException {
// Set a suitable storage path for the wallet to avoid problems with file system permissions.
// Android applications must necessarily configure this: make sure you replace the ´com.example.myapplication´ with your own app naming.
String storagePath = "/data/data/com.example.myapplication/";
// Set up and store the wallet.
Wallet wallet = new Wallet(new WalletConfig()
.withClientOptions(new ClientConfig().withNodes("https://api.testnet.shimmer.network"))
.withSecretManager(new StrongholdSecretManager("PASSWORD_FOR_ENCRYPTION", null, storagePath + "stronghold/vault.stronghold"))
.withCoinType(CoinType.Shimmer)
.withStoragePath(storagePath)
);
// Store the mnemonic in the Stronghold vault.
wallet.storeMnemonic(DEFAULT_DEVELOPMENT_MNEMONIC);
// Create an account.
AccountHandle a = wallet.createAccount("Alice");
// Print the account.
System.out.println(a);
}
}
What's Next?
Now that you are up and running, you can get acquainted with the library using its how-to guides and the repository's code examples.
Instead, build everything from scratch yourself:
If you don't like to use the provided libraries and instead want to build everything yourself from scratch:
Build for Android:
Requirements:
- minimum Java version >= 8
- Android Studio with NDK
- latest stable version of Rust
- cargo-ndk (https://github.com/bbqsrc/cargo-ndk)
- Generate the JAR:
git clone https://github.com/iotaledger/wallet.rs
cd wallet.rs/bindings/java
./gradlew jarWithoutNativeLibs
You will find the built JAR in the
lib/build/libs
directory. Add it as a library to your Android project.Install the Android targets you want to support:
rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android
- Build the native library for your Android targets:
cd lib/native
cargo ndk -t arm64-v8a -t armeabi-v7a -t x86 -t x86_64 -o ./jniLibs build --release
- On success, you will find the built native libraries in the
jniLibs/
directory like:
── jniLibs/
├── arm64-v8a/ <-- ARM 64bit
│ └── libiota-wallet.so
├── armeabi-v7a/ <-- ARM 32bit
│ └── libiota-wallet.so
│── x86/ <-- Intel 32bit
│ └── libiota-wallet.so
└── x86_64/ <-- Intel 64bit
└── libiota-wallet.so
- Each folder is missing its
libc++_shared.so
. You can find them in the configured Android NDK folder like:
find $ANDROID_NDK_HOME -name "libc++_shared.so"
- Copy the found
libc++_shared.so
files to their respective folder inside thejniLibs
directory:
── jniLibs/
├── arm64-v8a/ <-- ARM 64bit
│ └── libiota-wallet.so
│ └── libc++_shared.so
├── armeabi-v7a/ <-- ARM 32bit
│ └── libiota-wallet.so
│ └── libc++_shared.so
│── x86/ <-- Intel 32bit
│ └── libiota-wallet.so
│ └── libc++_shared.so
└── x86_64/ <-- Intel 64bit
└── libiota-wallet.so
└── libc++_shared.so
- Add the
jniLibs
folder with its contents to your Android Studio project as shown below:
project/
├──src/
└── main/
├── AndroidManifest.xml
├── java/
└── jniLibs/
├── arm64-v8a/ <-- ARM 64bit
│ └── libiota-wallet.so
│ └── libc++_shared.so
├── armeabi-v7a/ <-- ARM 32bit
│ └── libiota-wallet.so
│ └── libc++_shared.so
│── x86/ <-- Intel 32bit
│ └── libiota-wallet.so
│ └── libc++_shared.so
└── x86_64/ <-- Intel 64bit
└── libiota-wallet.so
└── libc++_shared.so
Build for Linux, macOS, Windows
Please note, following instructions build the library for your host OS/architecture only.
Requirements:
- minimum Java version >= 8
- latest stable version of Rust
- Generate the JAR:
git clone https://github.com/iotaledger/wallet.rs
cd wallet.rs/bindings/java
./gradlew jar
- You will find the built JAR in the
lib/build/libs
directory. Add it as a library to your Java project.