jNano

A comprehensive Java library for the Nano (and Banano) cryptocurrency.

License

License

Categories

Categories

JNA Development Tools Native
GroupId

GroupId

uk.oczadly.karl
ArtifactId

ArtifactId

jnano
Last Version

Last Version

2.20.1
Release Date

Release Date

Type

Type

jar
Description

Description

jNano
A comprehensive Java library for the Nano (and Banano) cryptocurrency.
Project URL

Project URL

https://github.com/koczadly/jNano
Source Code Management

Source Code Management

http://github.com/koczadly/jnano/tree/master

Download jnano

How to add to project

<!-- https://jarcasting.com/artifacts/uk.oczadly.karl/jnano/ -->
<dependency>
    <groupId>uk.oczadly.karl</groupId>
    <artifactId>jnano</artifactId>
    <version>2.20.1</version>
</dependency>
// https://jarcasting.com/artifacts/uk.oczadly.karl/jnano/
implementation 'uk.oczadly.karl:jnano:2.20.1'
// https://jarcasting.com/artifacts/uk.oczadly.karl/jnano/
implementation ("uk.oczadly.karl:jnano:2.20.1")
'uk.oczadly.karl:jnano:jar:2.20.1'
<dependency org="uk.oczadly.karl" name="jnano" rev="2.20.1">
  <artifact name="jnano" type="jar" />
</dependency>
@Grapes(
@Grab(group='uk.oczadly.karl', module='jnano', version='2.20.1')
)
libraryDependencies += "uk.oczadly.karl" % "jnano" % "2.20.1"
[uk.oczadly.karl/jnano "2.20.1"]

Dependencies

compile (5)

Group / Artifact Type Version
com.google.code.gson : gson jar 2.8.6
com.rfksystems : blake2b jar 1.0.0
org.java-websocket : Java-WebSocket jar 1.5.1
net.i2p.crypto : eddsa jar 0.3.0
org.jocl : jocl jar 2.0.2

test (1)

Group / Artifact Type Version
junit : junit jar 4.13.1

Project Modules

There are no modules declared in this project.

jNano | Java library for Nano

Maven Central

jNano is a Java library used to make integrations with the Nano cryptocurrency simple. This library allows you to interface with the node via RPC requests, and also provides many native tools and utilities so that a node isn't always necessary.

Nano is a crypto-currency which offers instantaneous and fee-less transactions. For more information, visit https://nano.org.


Technical details

  • This library requires Java 8+ (module uk.oczadly.karl.jnano for versions 9+)
  • Fully compatible with clone cryptocurrencies (eg. Banano)
  • Built and managed through Maven
  • List of dependencies

Features

This library provides simple access to the following facilities:


Usage

Download

This project is hosted on Maven Central. You can also download the compiled JAR directly from here.

Maven

<dependency>
    <groupId>uk.oczadly.karl</groupId>
    <artifactId>jnano</artifactId>
    <version>2.20.1</version>
</dependency>

Gradle

dependencies {
    implementation 'uk.oczadly.karl:jnano:2.20.1'
}

Documentation

Examples

RPC Queries [Wiki]

To make queries to an external Nano node through the RPC system, you will need to use the RpcQueryNode class. You can customize these objects even further by constructing using the nested Builder class.

RpcQueryNode rpc = new RpcQueryNode();          // Using localhost:7076
RpcQueryNode rpc = RpcServiceProviders.nanex(); // Using nanex.cc public API

This example will print an account's balance to the console using a synchronous (blocking) call.

// Construct and execute the request, and obtain the response
ResponseBalance balance = rpc.processRequest(new RequestAccountBalance(
        "nano_34qjpc8t1u6wnb584pc4iwsukwa8jhrobpx4oea5gbaitnqafm6qsgoacpiz"));

// Handle the result object however you wish (eg. print the balance)
System.out.println("Account balance: " + balance.getTotal());

WebSockets (listening for blocks) [Wiki]

The following will create a WebSocket listener which connects to port 7078 on localhost. For each new block confirmed by the node, the hash and type will be printed to the console.

NanoWebSocketClient ws = new NanoWebSocketClient(); // Defaults to localhost:7078
ws.connect(); // Connect to the endpoint

// Register a listener (will be called for each new block)
ws.getTopics().topicConfirmedBlocks().registerListener((message, context) -> {
    // Print the hash and type of all confirmed blocks
    System.out.printf("Confirmed block: %s (%s)%n",
            message.getHash(), message.getBlock().getType());
});

// Subscribe to the block confirmations topic
ws.getTopics().topicConfirmedBlocks().subscribeBlocking(new TopicConfirmation.SubArgs()
        .includeBlockContents() // Include block info in messages
        .filterAccounts( // Only receive blocks for these accounts
                "nano_34qjpc8t1u6wnb584pc4iwsukwa8jhrobpx4oea5gbaitnqafm6qsgoacpiz",
                "nano_1ipx847tk8o46pwxt5qjdbncjqcbwcc1rrmqnkztrfjy5k7z4imsrata9est"));

Block Creation [Wiki]

The following sample will create a new state block. The block will be signed using the provided private key, and work will be generated in the JVM using the CPU.

WorkGenerator workGenerator = new CPUWorkGenerator(); // Note: construct once and re-use

StateBlock block = StateBlock.builder()
        .subtype(StateBlockSubType.OPEN)
        .link("BF4A559FEF44D4A9C9CEF4972886A51FC83AD1A2BEE4CDD732F62F3C166D6D4F")
        .balance("123000000000000000000000000")
        .generateWork(workGenerator)
        .buildAndSign("A3293644AC105DEE5A0202B7EF976A06E790908EE0E8CC43AEF845380BFF954E"); // Private key

String hash = block.getHash().toHexString(); // Hashes the block
String blockJson = block.toJsonString(); // Serializes the block to JSON

Dependencies

This project requires the following dependencies, which are included automatically through Maven:


If you found this library useful and would like to support my work, donations may be sent to nano_34qjpc8t1u6wnb584pc4iwsukwa8jhrobpx4oea5gbaitnqafm6qsgoacpiz - any amount would be greatly appreciated :D

Versions

Version
2.20.1
2.20.0
2.19.1
2.19.0
2.18.1
2.18.0
2.17.3
2.17.2
2.17.1
2.17.0
2.16.0
2.15.0
2.14.0
2.13.0
2.12.0-V21.2
2.11.0-V21.2
2.10.2-V21.2
2.10.1-V21.2
2.10.0-V21.2
2.9.1-V21.2
2.9.0-V21.2
2.8.1-V21.2
2.8.0-V21.2
2.7.5-V21.2
2.7.4-V21.2
2.7.3-V21.2
2.7.2-V21.2
2.7.1-V21.2
2.7.0-V21.2
2.6.7-V21
2.6.6-V21
2.6.5-V21
2.6.4-V21
2.6.3-V21
2.6.2-V21
2.6.1-V21
2.6.0-V21
2.5.10-V21
2.5.9-V21
2.5.8-V21
2.5.7-V21
2.5.6-V21
2.5.5-V21
2.5.4-V21
2.5.3-V21
2.5.2-V21
2.5.1-V21
2.5.0-V21
2.4.2-V20
2.4.1-V20
2.4.0-V20
2.3.0-V20
2.2.0-V20
2.1.0-V20
2.0.1-V20
2.0.0-V19
1.0.0