waves_logo Docs
  • Overview
    Overview
  • How-to Guides
    • Reading Blockchain Data
      Reading Blockchain Data
    • Creating & Broadcasting Transactions
      Creating & Broadcasting Transactions
    • Tokenization
      Tokenization
    • Airdrop
      Airdrop
    • Payments
      Payments
    • Exchange Tokens
      Exchange Tokens
    • Simple Voting
      Simple Voting
    How-to Guides
  • Waves Smart Contracts
    Waves Smart Contracts
  • dApp
    • Creating & Launching dApp
      Creating & Launching dApp
    dApp
  • Smart Account
    • Creating smart account
      Creating smart account
    • Creating and deploying a script manually
      Creating and deploying a script manually
    • Video tutorials
      • Introduction to the Waves blockchain, Waves Smart Accounts and Waves Smart Assets
        Introduction to the Waves blockchain, Waves Smart Accounts and Waves Smart Assets
      • Waves Smart Account with multisignature
        Waves Smart Account with multisignature
      • Waves Smart Account with escrow service
        Waves Smart Account with escrow service
      • Creating multisignature account via Waves IDE tools
        Creating multisignature account via Waves IDE tools
      • Creating multisignature account via Waves Client
        Creating multisignature account via Waves Client
      • Waves console explained
        Waves console explained
      Video tutorials
    Smart Account
  • Smart Asset
    Smart Asset
  • Developer Tools
    • Waves IDE
      Waves IDE
    • Visual Studio Code Extension
      Visual Studio Code Extension
    • Surfboard
      Surfboard
    • Ride REPL
      Ride REPL
    Developer Tools
  • Signer ◆
    Signer ◆
  • Waves API
    • Data Service API
      Data Service API
    • Node REST API 🡥
      Node REST API 🡥
    • Node gRPC Server 🡥
      Node gRPC Server 🡥
    • Blockchain Updates 🡥
      Blockchain Updates 🡥
    Waves API
  • Client libraries
    • Waves transactions
      Waves transactions
    • WavesJ
      WavesJ
    • WavesC
      WavesC
    • GoWaves
      GoWaves
    • Community libraries
      Community libraries
    Client libraries
      • English
      • Русский
      On this page
        • Using WavesJ in your project
        • Basic Usage
        • Building the library
      waves_logo Docs

          # WavesJ

          It's a Java library for interacting with the Waves blockchain.

          Supports node interaction, offline transaction signing, Matcher orders, and creating addresses and keys.

          # Using WavesJ in your project

          Use the codes below to add WavesJ as a dependency for your project.

          # Maven:
          <dependency>
              <groupId>com.wavesplatform</groupId>
              <artifactId>wavesj</artifactId>
              <version>0.8</version>
          </dependency>
          
          # Gradle:
          compile group: 'com.wavesplatform', name: 'wavesj', version: '0.2'
          
          # SBT:
          libraryDependencies += "com.wavesplatform" % "wavesj" % "0.2"
          

          This library's page at Maven Central

          # Basic Usage

          Create an account from a private key ('T' for testnet):

          String seed = "health lazy lens fix dwarf salad breeze myself silly december endless rent faculty report beyond";
          PrivateKeyAccount account = PrivateKeyAccount.fromSeed(seed, 0, Account.TESTNET);
          byte[] publicKey = account.getPublicKey();
          String address = account.getAddress();
          

          Create a Node and learn a few things about blockchain:

          Node node = new Node("https://my.waves.node/");
          System.out.println("Current height is " + node.getHeight());
          System.out.println("My balance is " + node.getBalance(address));
          System.out.println("With 100 confirmations: " + node.getBalance(address, 100));
          

          Send some money to a buddy:

          String buddy = "3N9gDFq8tKFhBDBTQxR3zqvtpXjw5wW3syA";
          String txId = node.transfer(account, buddy, 1_00000000, 100_000, "Here's for you");
          

          Sign a transaction offline:

          Transaction tx = Transaction.makeTransferTx(account, buddy, 1_00000000, Asset.WAVES, 100_000, Asset.WAVES, "");
          System.out.println("JSON encoded data: " + tx.getJson());
          System.out.println("Server endpoint to send this JSON to: " + tx.getEndpoint());
          

          Now send it from an online machine:

          node.send(tx);
          

          Create an order:

          Node matcher = new Node("https://testnode2.wavesnodes.com");
          String matcherKey = matcher.getMatcherKey();
          String wbtcId = "Fmg13HEHJHuZYbtJq8Da8wifJENq8uBxDuWoP9pVe2Qe";
          Order order = matcher.createOrder(alice, matcherKey,
                          new AssetPair(Asset.WAVES, wbtcId),
                          // buy 10 WAVES at 0.00090000 WBTC each
                          Order.Type.BUY, 90_000, 10 * Asset.TOKEN,
                          // make order valid for 1 hour
                          System.currentTimeMillis() + 3_600_000, MATCHER_FEE);
          System.out.printf("Filed order " + order.id);
          

          There are some examples undersrc/examples/java.

          # Building the library

          To build from scratch, run

          mvn clean package
          

          The outputs are placed under thetargetdirectory.

          Waves transactions
          WavesC
          Waves transactions
          WavesC