/everscale-client-java

Java library for TON-SDK Client

Primary LanguageJavaApache License 2.0Apache-2.0

Java library for Everscale Client

SDK version

The Library is a binding for Everscale Client written in Java that act as a bridge between Everscale Client and a Java application. The library includes original EVER-SDK Library with incorporated support of Java Native Interface (JNI) which allows direct access to Everscale Client from Java Virtual Machine.

Code Generation

The most of the library source code is generated from api.json by script ./binding/gen-java.js. To use the script you must have Node.js installed.

Prerequisites

  • Use the following command to install Java JDK:
    $ sudo apt-get install default-jdk
  • Use the following command to install maven:
    $ sudo apt-get install maven
    $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Build

  • To build, enter the following command:
    $ build.sh
  • To generate Java API Documentation, use:
    $ mvn javadoc:javadoc
  • You can find the generated documentation under ${Project_basedir}/binding/target/site/apidocs
  • To run tests, enter the following command:
    $ mvn test
  • If succeed, you can find "everscale-client-binding-1.44.2-jar-with-dependencies.jar" file located under ${Project_basedir}/binding/target

Clean

  • To clean the generated files, enter the following command:
    $ mvn clean

How to use the library

Once the build succeed you will have the library installed to your local maven repository. To use it in your projects, add the dependency to pom.xml

    ...
    <dependency>
      <groupId>com.radiance.tonclient</groupId>
      <artifactId>everscale-client-binding</artifactId>
      <version>1.44.2</version>
    </dependency>
    ...

Example of usage:

    // At the beginning TON Context must be created
    // Configuration parameters are passed as a json string
    TONContext context = TONContext.create("{\"network\":{\"server_address\":\"https://net.ton.dev/graphql\"}}");

    /* Alternatively TON context can be configured via ClientConfig object
    TONContext context = TONContext.create(new ClientConfig(
        new NetworkConfig("https://net.ton.dev/graphql")
    ));
    */

    try {
        // TON methods can be invoked via context directly ...
        String randomBytes = context
            .requestJSON("crypto.generate_random_bytes", "{\"length\":12}")
            .get()
            .findValue("bytes").asText();
        System.out.println("Random bytes: '" + randomBytes + "'");

        // ... or using convenience classes
        Crypto crypto = new Crypto(context);
        randomBytes = crypto.generateRandomBytes(12).get();
        System.out.println("Random bytes: '" + randomBytes + "'");
    } finally {
        // context should be destroyed after using
        context.destroy();
    }

See also