Java SDK
Esta página aún no está disponible en tu idioma.
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.
Installation
Section titled “Installation”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>Manual Installation
Section titled “Manual Installation”If you prefer to build from source, you can clone the repository and install it locally:
git clone https://github.com/aptos-labs/japtos.gitcd japtosmvn clean installKey Features
Section titled “Key Features”- 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
Examples
Section titled “Examples” Quickstart Get started with the Java SDK in minutes
Account Management Learn how to create and manage accounts, including multi-signature and HD wallets
Building Transactions Learn how to build, sign, and submit transactions
Examples Explore comprehensive examples in the SDK repository
Network Support
Section titled “Network Support”The SDK supports all Aptos networks:
import com.aptoslabs.japtos.api.AptosConfig;import com.aptoslabs.japtos.client.AptosClient;
// Connect to different networksAptosConfig config = AptosConfig.builder() .network(AptosConfig.Network.MAINNET) // or TESTNET, DEVNET, LOCALNET .build();
AptosClient client = new AptosClient(config);Transfer APT Example
Section titled “Transfer APT Example”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 clientAptosConfig config = AptosConfig.builder() .network(AptosConfig.Network.DEVNET) .build();AptosClient client = new AptosClient(config);
// Create accountsEd25519Account 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 transactionModuleId 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 IDlong sequenceNumber = client.getAccountSequenceNumber(alice.getAccountAddress());int chainId = client.getChainId();
// Build and sign transactionRawTransaction 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 transactionPendingTransaction pendingTx = client.submitTransaction(signedTx);Transaction tx = client.waitForTransaction(pendingTx.getHash());
System.out.println("Transaction completed: " + tx.isSuccess());