Published 1 November 2018

Creating a console application on Java using Credits API and Maven. Cash transfer




Java IDE (optional, JetBrains IntelliJ is considered)

Text editor (for example, Visual Studio Code)

Maven (installation is described in the "Installing Maven on Windows 10" article)

GIT (installation)

A prerequisite for the operation is to run the following Java application from the standard Credits delivery (port 9080 should not be busy):

start call java -jar contract-executor.jar

Assembly. Sequence of steps

Assembly. Sequence of steps

This article is the next step for "Creating user tools (applications) on the basis of the Credits API and Java".

It is assumed that the application is already created and you want to implement the functionality of coin transfer using the Credits API.

We will consider source codes of Credits Desktop Wallet app a source of information and methods

The following methods are wrappers around the Credits API:

private static BigDecimal getBalance(String account, ApiClient client)

      throws CreditsCommonException, LevelDbClientException, CreditsNodeException {

  return client.getBalance(Converter.decodeFromBASE58(account), (byte)1);


public static void callTransactionFlow(ApiClient client,

                                     PrivateKey privateKey,

                                     long innerId,

                                     String source,

                                     String target,

                                     BigDecimal amount,

                                     BigDecimal balance,

                                     byte currency,

                                     BigDecimal fee) throws LevelDbClientException,

                                     CreditsNodeException, CreditsCommonException {

   TransactionStruct tStruct = new TransactionStruct(innerId, source, target, amount, fee, currency, null);

  ByteBuffer signature= Utils.signTransactionStruct(tStruct, privateKey);

  TransactionFlowData transactionFlowData =

          new TransactionFlowData(innerId,






                                  signature.array(), fee);



private static void Transfer(String account,

                           PrivateKey privateKey,

                           long innerId,

                           ApiClient client,

                           BigDecimal amount,

                           String toAddress) throws CreditsCommonException, LevelDbClientException, CreditsNodeException {







                      new BigDecimal(1000000),


                      new BigDecimal(0.1));


Considering the problem from the applied point of view, namely, the transfer from wallet to wallet, we are interested in the "Transfer" method with the following input parameters:

String account - public key of the wallet

PrivateKey privateKey - private key of the wallet

long innerId - time variable (transaction date)

ApiClient client - object api client

String toAddress - address of the destination wallet

The following is the "main" method of our console utility. You can see that the parameters for calling the "Transfer" method are "sewn" into the source code, these parameters may be put in the command line arguments and be set when the utility is called through the command line.

public static void main(String[] args) throws CreditsCommonException, LevelDbClientException, CreditsNodeException {

  String account = "H5ptdUUfjJBGiK2X3gN2EzNYxituCUUnXv2tiMdQKP3b";

  String privateKeyString = "3Ki86Y3dy8enEgM1LXL97oQ6zLnhVbjJPpWAdqhgkAh7uFab37ergRWJxyDDsa46ra3UiQXqe2rW7JrJPkekBWMs";

  ApiClient client = ApiClient.getInstance("", 9090);

  BigDecimal balance = getBalance(account, client);


  PrivateKey privateKey = Ed25519.bytesToPrivateKey(Converter.decodeFromBASE64(privateKeyString));

  Transfer(account, privateKey, new Date().getTime(), client, new BigDecimal(1000), "6zxLh3nbbtxt36ED211Y3askbbSY4E1iV98TKcFzjoUk");



Votes 0, average rating 0