Skip to content

Java SDK

Github Repo Stars

Static Badge

The Java SDK (Japtos) allows you to connect, explore, and interact with the Aptos blockchain from Java applications. It provides comprehensive support for account management, transaction signing, multi-signature accounts, and hierarchical deterministic wallets.

Add the GitHub Packages repository and dependency to your pom.xml:

<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/aptos-labs/japtos</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aptos-labs</groupId>
<artifactId>japtos</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>

If you prefer to build from source, you can clone the repository and install it locally:

Terminal window
git clone https://github.com/aptos-labs/japtos.git
cd japtos
mvn clean install
  • Advanced Cryptography: Ed25519 and MultiEd25519 signature schemes
  • Hierarchical Deterministic Wallets: BIP39/BIP44 support with mnemonic phrases
  • Multi-Signature Accounts: Threshold-based multi-signature transactions
  • BCS Serialization: Binary Canonical Serialization for Aptos transactions
  • HTTP Client: Robust REST client for Aptos API interactions
  • Comprehensive Testing: Extensive test suite covering all functionality

The SDK supports all Aptos networks:

import com.aptoslabs.japtos.api.AptosConfig;
import com.aptoslabs.japtos.client.AptosClient;
// Connect to different networks
AptosConfig config = AptosConfig.builder()
.network(AptosConfig.Network.MAINNET) // or TESTNET, DEVNET, LOCALNET
.build();
AptosClient client = new AptosClient(config);

Here’s a quick example of how to transfer APT tokens:

import com.aptoslabs.japtos.account.Ed25519Account;
import com.aptoslabs.japtos.client.AptosClient;
import com.aptoslabs.japtos.api.AptosConfig;
import com.aptoslabs.japtos.transaction.*;
import com.aptoslabs.japtos.types.*;
// Setup client
AptosConfig config = AptosConfig.builder()
.network(AptosConfig.Network.DEVNET)
.build();
AptosClient client = new AptosClient(config);
// Create accounts
Ed25519Account alice = Ed25519Account.generate();
Ed25519Account bob = Ed25519Account.generate();
// Fund accounts (devnet only)
client.fundAccount(alice.getAccountAddress(), 100_000_000);
client.fundAccount(bob.getAccountAddress(), 100_000_000);
// Build transfer transaction
ModuleId moduleId = new ModuleId(
AccountAddress.fromHex("0x1"),
new Identifier("coin")
);
TransactionPayload payload = new EntryFunctionPayload(
moduleId,
new Identifier("transfer"),
Arrays.asList(new TypeTag.Struct(new StructTag(
AccountAddress.fromHex("0x1"),
new Identifier("aptos_coin"),
new Identifier("AptosCoin"),
Arrays.asList()
))),
Arrays.asList(
new TransactionArgument.AccountAddress(bob.getAccountAddress()),
new TransactionArgument.U64(1_000_000L) // 0.01 APT
)
);
// Get account sequence number and chain ID
long sequenceNumber = client.getAccountSequenceNumber(alice.getAccountAddress());
int chainId = client.getChainId();
// Build and sign transaction
RawTransaction rawTx = new RawTransaction(
alice.getAccountAddress(),
sequenceNumber,
payload,
1000000L, // maxGasAmount
100L, // gasUnitPrice
System.currentTimeMillis() / 1000 + 3600, // expiration
chainId
);
SignedTransaction signedTx = new SignedTransaction(
rawTx,
alice.signTransactionWithAuthenticator(rawTx)
);
// Submit and wait for transaction
PendingTransaction pendingTx = client.submitTransaction(signedTx);
Transaction tx = client.waitForTransaction(pendingTx.getHash());
System.out.println("Transaction completed: " + tx.isSuccess());