Java API library for NEM.io blockchain platform. This directly calls the https://github.com/NEMModules/nem.core that then calls the endpoints based on https://bob.nem.ninja/docs/
Library has the following features/functionalities
- Initiate a transfer transactoin (including mosaic)
- Initiate a multisig transaction (including mosaic)
- Cosign a multisig transaction
- Configurable Custom Fee Calculation
- Get All Transaction (Confirmed/Unconfirmed/Incoming/Outgoing) for an Account
- Get All Owned Mosaics of an Account
- Get Block and Chain Info
- Node Information and Check Node Heartbeats
- Transaction Monitoring (using nem-transaction-monitor)
- Java 1.8
- nem.core
git clone https://github.com/NEMPH/nem.core.git
cd nem.core
mvn clean install
build the nem-apps-lib after.
git clone https://github.com/NEMPH/nem-apps-lib.git
cd nem-apps-lib
mvn clean install
Import it as a maven dependency
<dependency>
<groupId>io.nem.apps</groupId>
<artifactId>nem-apps-lib</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
Before starting, make sure you have the node endpoint is all set. Note that this should only be called once.
ConfigurationBuilder.nodeNetworkName("<network name>")
.nodeNetworkProtocol("http")
.nodeNetworkUri("<node url>")
.nodeNetworkPort("7895")
.setup();
You can also change the node endpoint on the fly.
Globals.setNodeEndpoint(new NodeEndpoint("http","<node url>",7895));
Use the following set of builders to create transactions.
TransferTransactionBuilder.sender(new Account(this.senderPrivateKeyPair))
.recipient(new Account(this.recipientPublicKeyPair))
.amount(0l)
.buildAndSendTransaction();
TransferTransaction transaction = TransferTransactionBuilder
.sender(new Account(this.senderPrivateKeyPair)) // multisig account
.recipient(new Account(this.recipientPublicKeyPair))
.amount(0l)
.buildTransaction();
MultisigTransactionBuilder.sender(this.senderPrivateAccount) // co-signer as sender
.otherTransaction(transaction)
.buildAndSendMultisigTransaction();
MultisigSignatureTransactionBuilder.multisig(this.multisigPublicAccount) // multisig account
.signer(this.senderPrivateAccount) // signer
.otherTransaction(Hash.fromHexString("hash")) // hash
.buildMultisigSignatureTransaction();
MultisigSignatureTransactionBuilder.multisig(this.multisigPublicAccount) // multisig
.startAssignSigners()
.addSigner(this.senderPrivateAccount1) // signer 1
.addSigner(this.senderPrivateAccount2) // signer 2
.endAssignSigners()
.otherTransaction(Hash.fromHexString("hash"))
.coSign();
Developers can catch callbacks before and after a transaction is made. All the developer needs to do is define a Callback class and use it either on per Transaction or for All Transaction.
Fees can be calculated either on a Global level or per transaction.
Fees can also be configurable. With the API, the developers can put in their own Fee Calculation on either per Transaction or for All Transaction.
ConfigurationBuilder.nodeNetworkName("<network name>").nodeNetworkProtocol("http")
.nodeNetworkUri("<node url>").nodeNetworkPort("7895")
.transactionFee(new TransactionFeeCalculatorAfterFork()) // global
.setup();
fee can also be set on the transaction level via the fee() method.
TransferTransactionBuilder
.sender(new Account(this.senderPrivateKeyPair))
.recipient(new Account(this.recipientPublicKeyPair))
.amount(0l)
.fee(Amount.fromMicroNem(0l)) // fee
.buildAndSendTransaction();
fee calculation can also be set on the transaction level using the feeCalculator() method.
TransferTransactionBuilder
.sender(new Account(this.senderPrivateKeyPair))
.recipient(new Account(this.recipientPublicKeyPair))
.amount(0l)
.feeCalculator(new TransactionFeeCalculatorAfterForkForApp()) // custom fee calculator
.buildAndSendTransaction();
Use the following static methods to encode and decode Secure Message Payloads.
SecureMessageEncoder.encode(Account senderPrivateKey, Account recipientPublicKey, String message)
//or
SecureMessageEncoder.encode(String senderPrivateKey, String recipientPublicKey, String message)
SecureMessageDecoder.decode(Account recipientPrivateKey, Account senderPublicKey, String encryptedPayload) SecureMessageDecoder.decode(Account recipientPrivateKey, Account senderPublicKey, byte[] encryptedPayload)
//or
SecureMessageDecoder.decode(String recipientPrivateKey, String senderPublicKey, String encryptedPayload)
SecureMessageDecoder.decode(String recipientPrivateKey, String senderPublicKey, byte[] encryptedPayload)
CryptoEngine engine = CryptoEngines.ed25519Engine();
//encrypt
byte[] encrypted = engine
.createBlockCipher(
new KeyPair(PrivateKey.fromHexString(xPvkey), engine),
new KeyPair(PublicKey.fromHexString(xPubkey), engine))
.encrypt("hello".getBytes());
// decrypt
byte[] decrypted = engine
.createBlockCipher(
new KeyPair(PublicKey.fromHexString(xPubkey), engine),
new KeyPair(PrivateKey.fromHexString(xPvkey), engine)).decrypt(encrypted);
GeneratedAccount AccountApi.generateAccount()
AccountMetaDataPair AccountApi.getAccountByAddress(String address)
List<TransactionMetaDataPair> AccountApi.getAllTransactions(String address)
List<TransactionMetaDataPair> AccountApi.getAllConfirmedTransactions(String address)
List<TransactionMetaDataPair> AccountApi.getAllUnconfirmedTransactions(String address)
List<TransactionMetaDataPair> AccountApi.getIncomingTransactions(String address)
List<TransactionMetaDataPair> AccountApi.getOutgoingTransactions(String address)
List<Mosaic> AccountApi.getAccountOwnedMosaic(String address)
Block BlockApi.getBlockByHeight(int blockHeight)
Block getBlockAfterGivenBlockHeight(int height)
Block ChainApi.getChainHeight()
Block ChainApi.getChainScore()
Block ChainApi.getChainLastBlock()
boolean ValidationApi.isAddressValid(String address)
boolean ValidationApi.isAddressValid(String address, NodeEndpoint nodeEndpoint)
boolean ValidationApi.isAddressValid(String address, String protocol, String host, int port)
boolean ValidationApi.isAddressPatternValid(String address)
Node NodeApi.getNodeInfo()
NisNodeInfo NodeApi.getNodeExtendedInfo()
NemRequestResult NodeApi.getNemNodeHeartBeat()
git clone https://github.com/NEMPH/nem-transaction-monitor.git
cd nem-transaction-monitor
mvn clean install
Import maven dependency
<dependency>
<groupId>io.nem.apps</groupId>
<artifactId>nem-transaction-monitor</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
WsNemTransactionMonitor.init().host("<node url>").port("7895").wsPort("7778")
.addressToMonitor("MDYSYWVWGC6JDD7BGE4JBZMUEM5KXDZ7J77U4X2Y") // address to monitor
.subscribe(io.nem.utils.Constants.URL_WS_TRANSACTIONS, new TransactionMonitor()) // multiple subscription and a handler
.subscribe(io.nem.utils.Constants.URL_WS_UNCONFIRMED, new UnconfirmedTransactionMonitor())
.monitor(); // trigger the monitoring process
public class CustomTransactionMonitor implements TransactionMonitorHandler {
@Override
public Type getPayloadType(StompHeaders headers) {
return String.class;
}
@Override
public void handleFrame(StompHeaders headers, Object payload) {
System.out.println(payload.toString()); // handle the payload.
}
}
Tips are appreciated but not required. 💪 🤘
XEM: NA6IT2-ZSTQLT-YO223Z-ZMH2J7-2GVG7G-ZY72FN-47IF
BTC: 3JYAYPxN9RL4UvbxMd1svbQynMpFbf5ehy
Copyright (c) 2017