- Notifications
You must be signed in to change notification settings - Fork0
A comprehensive Java library for the Nano cryptocurrency.
License
blockracer/jNano
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
jNano is a Java library used to make integrations with theNano cryptocurrency simple.This library allows you to interface with thenodevia 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, visithttps://nano.org.
- This library requiresJava 8+ (module
uk.oczadly.karl.jnano
for versions 9+) - Fully compatible with clone cryptocurrencies (eg.Banano)
- Built and managed throughMaven
- List of dependencies
This library provides simple access to the following facilities:
- RPC queries
- WebSocket notifications
HTTP block callback server(deprecated, prefer websockets where possible)- Various built-in utilities:
- Blockcreation /signing /hashing
- Work generation (with support for CPU, GPU and theDPoW service)
- Accountparsing /validation
- Unit conversions
- Constants for Nano (and Banano)
This project is hosted on Maven Central. You can also download the compiled JAR directly fromhere.
<dependency> <groupId>uk.oczadly.karl</groupId> <artifactId>jnano</artifactId> <version>2.20.1</version></dependency>
dependencies { implementation'uk.oczadly.karl:jnano:2.20.1'}
RPC Queries[Wiki]
To make queries to an external Nano node through the RPC system, you will need to use theRpcQueryNodeclass. You can customize these objects even further by constructing using the nestedBuilder
class.
RpcQueryNoderpc =newRpcQueryNode();// Using localhost:7076RpcQueryNoderpc =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 responseResponseBalancebalance =rpc.processRequest(newRequestAccountBalance("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 port7078
onlocalhost
. For each new blockconfirmed by the node, the hash and type will be printed to the console.
NanoWebSocketClientws =newNanoWebSocketClient();// Defaults to localhost:7078ws.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 blocksSystem.out.printf("Confirmed block: %s (%s)%n",message.getHash(),message.getBlock().getType());});// Subscribe to the block confirmations topicws.getTopics().topicConfirmedBlocks().subscribeBlocking(newTopicConfirmation.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 newstate
block. The block will be signed using the provided private key, andwork will be generated in the JVM using the CPU.
WorkGeneratorworkGenerator =newCPUWorkGenerator();// Note: construct once and re-useStateBlockblock =StateBlock.builder() .subtype(StateBlockSubType.OPEN) .link("BF4A559FEF44D4A9C9CEF4972886A51FC83AD1A2BEE4CDD732F62F3C166D6D4F") .balance("123000000000000000000000000") .generateWork(workGenerator) .buildAndSign("A3293644AC105DEE5A0202B7EF976A06E790908EE0E8CC43AEF845380BFF954E");// Private keyStringhash =block.getHash().toHexString();// Hashes the blockStringblockJson =block.toJsonString();// Serializes the block to JSON
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 tonano_34qjpc8t1u6wnb584pc4iwsukwa8jhrobpx4oea5gbaitnqafm6qsgoacpiz
-any amount would be greatly appreciated :D
About
A comprehensive Java library for the Nano cryptocurrency.
Resources
License
Stars
Watchers
Forks
Packages0
Languages
- Java99.6%
- C0.4%