The official Java client library for interacting with the legacy Tangle (deprecated since Chrysalis)
About ◈ Prerequisites ◈ Installation ◈ Getting started ◈ API reference ◈ Examples ◈ Change logs ◈ Supporting the project ◈ Joining the discussion
This java client is no longer usable in the new Chrysalis network. Please use the Java bindings generated for iota.rs. They can be found here
This was the official Java client library, which allows you to do the following:
- Create transactions
- Read transactions
- Sign transactions
- Generate addresses
This is beta software, so there may be performance and stability issues. Please report any issues in our issue tracker.
To use the IOTA Java client library, your computer must have the following minimum requirement:
- Java 6 (or higher)
The IOTA Java client library is available on [jitpack.io][jitpack].
To install the IOTA Java client library and its dependencies, you can use one of the following options:
- Download the library with Gradle
- Download the library with Maven
- Download the library manually
Add the following repository to your root
build.gradlefile (not your modulebuild.gradlefile):allprojects { repositories { maven { url 'https://jitpack.io' } } }
Add the following dependency to your module
build.gradlefile:dependencies { compile 'com.github.iotaledger:iota-java:1.0.0-beta8' }
- Add the following repository to your root
pom.xmlfile:<dependency> <groupId>org.iota</groupId> <artifactId>jota</artifactId> <classifier>jar-with-dependencies</classifier> <version>1.0.0-beta9</version> </dependency>
Add the following repository to your root
pom.xmlfile:<repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories>
Add the following dependency to your module
pom.xmlfile:<dependency> <groupId>com.github.iotaledger.iota-java</groupId> <artifactId>jota</artifactId> <classifier>jar-with-dependencies</classifier> <version>[VERSION_INFORMATION]</version> </dependency>
Change the value of the
<version>tag to either a release number or the first 10 characters of a Git commit hash:<version>b703ef3c05f05</version>or<version>1.0.0-beta9</version>
Note: Find the latest version on the Jitpack page.
Clone or download the GitHub repository.
Inside the project, you'll have the following directories:
- jota
- jota-parent
Import and reference the jota directory in your project For example in Eclipse:
right mouse on your project -> Properties -> Java Build Path -> Projects -> Add 'jota'In the jota directory, run the following command:
mvn clean install
You'll have a .jar file called jota-[VERSION]-jar-with-dependencies.jar, depending on your version of the library.
After you've installed the library, you can connect to an IRI node to send transactions to it and interact with the Tangle. An extended guide can be found on our documentation portal, we strongly recommend you to go here for starting off. A quick start tutorial is shown below.
To connect to a local IRI node on port 14265, do the following:
IotaAPIapi = newIotaAPI.Builder().build();
GetNodeInfoResponseresponse = api.getNodeInfo();To connect to a remote IRI node on port 14265, do the following:
IotaAPIapi = newIotaAPI.Builder()
.protocol("http")
.host("URL OF THE REMOTE IRI NODE")
.port(14265)
.build();
GetNodeInfoResponseresponse = api.getNodeInfo();Note: To separate your IRI node configuration from the implementation, you can also specify your IRI node configuration in a Java .properties file or as command line flags. These options are useful if you develop an open-source app which is deployed on a CI and don't want contributors to see the internal IRI node configuration.
To make the API read from this file, add the configuration to the builder like so: .config(new FileConfig("node_config.properties"))
Example .properties files
iota.node.protocol=httpiota.node.host=127.0.0.1iota.node.port=14265Most API calls are synchronous. Therefore, we recommend that you call the API from a background thread or a worker thread to stop the API from blocking other threads such as the UI or the main thread.
For a full list of API commands for the IOTA Java client library, go to the GitHub page.
Here are some of the most commonly used API functions:
getTransactionsObjectsfindTransactionObjectsgetTransactionsObjectsgetLatestInclusionbroadcastAndStoregetNewAddressgetInputsprepareTransferssendTrytessendTransferreplayBundlegetBundlegetTransfersinitiateTransfergetAccountData
We have a list of test cases in the src/test/java directory that you can use as a reference when developing apps with IOTA.
A good starter is the IotaAPITest case.
Here's how you could send a zero-value transaction, using the library. For the guide, see the documentation portal.
classSendData {
publicstaticvoidmain(String[] args) throwsArgumentException {
// Connect to a nodeIotaAPIapi = newIotaAPI.Builder()
.protocol("https")
.host("nodes.devnet.thetangle.org")
.port(443)
.build();
intdepth = 3;
intminimumWeightMagnitude = 9;
// Even though a seed is not necessary because zero value transactions are not signed,// the library requires a seed to send a transaction.// This seed can be any random string of 81 trytesStringmyRandomSeed = SeedRandomGenerator.generateNewSeed();
// Define any security level (like the seed, this is not used)intsecurityLevel = 2;
// Define an address.// This does not need to belong to anyone or have IOTA tokens.// It must only contain a maximum of 81 trytes// or 90 trytes with a valid checksumStringaddress = "ZLGVEQ9JUZZWCZXLWVNTHBDX9G9KZTJP9VEERIIFHY9SIQKYBVAHIMLHXPQVE9IXFDDXNHQINXJDRPFDXNYVAPLZAW";
// This is a zero-value transactionintvalue = 0;
// Define a message to send.// This message must include only ASCII characters.Stringmessage = TrytesConverter.asciiToTrytes("Hello world");
Stringtag = "HELLOWORLD";
TransferzeroValueTransaction = newTransfer(address, value, message, tag);
ArrayList<Transfer> transfers = newArrayList<Transfer>();
transfers.add(zeroValueTransaction);
// Create a bundle from the transfers list// and send the transaction to the nodetry { // Since we don't send any value, we can skip validation of inputsSendTransferResponseresponse = api.sendTransfer(myRandomSeed, securityLevel, depth, minimumWeightMagnitude, transfers, null, null, false, false, null);
System.out.println(response.getTransactions());
} catch (ArgumentExceptione) { // Handle errore.printStackTrace(); }
}
}- Changes in 1.0.0-beta9
- Changes in 1.0.0-beta8
- Changes in 1.0.0-beta7
- Changes in 1.0.0-beta6
- Changes in 1.0.0-beta5
- Changes in 1.0.0-beta4
- Changes in 1.0.0-beta3
- Changes in 1.0.0-beta2
- Changes in 1.0.0-beta1
- Changes in v0.9.10
- Changes in v0.9.6
- Changes in v0.9.5
- Changes in v0.9.4
- Changes in v0.9.3
- Changes in v0.9.2
- Changes in v0.9.1
If the IOTA Java client library has been useful to you and you feel like contributing, consider posting a bug report, feature request or a pull request.
We have some basic contribution guidelines to keep our code base stable and consistent.
If you want to get involved in the community, need help with getting setup, have any issues related with the library or just want to discuss blockchain, distributed ledgers, and IoT with other people, feel free to join our Discord.
