Kotlin SDK Quickstart
此内容尚不支持你的语言。
This quickstart gets you from dependency setup to a confirmed transaction using the current Kaptos API shape.
-
Install the SDK
Kaptos publishes multiplatform and platform-specific artifacts to Maven Central.
Multiplatform
Section titled “Multiplatform”kotlin {sourceSets {commonMain.dependencies {implementation("xyz.mcxross.kaptos:kaptos:<version>")}}}JVM (example)
Section titled “JVM (example)”dependencies {implementation("xyz.mcxross.kaptos:kaptos-jvm:<version>")} -
Configure the client
val aptos = Aptos(AptosConfig(settings = AptosSettings(network = Network.DEVNET,clientConfig = ClientConfig(maxRetries = 10),))) -
Read chain data
val ledgerInfo = aptos.getLedgerInfo().expect("Failed to fetch ledger info")println("Ledger version: ${ledgerInfo.ledgerVersion}")val chainId = aptos.getChainId().expect("Failed to fetch chain id")println("Chain id: $chainId") -
Create and fund accounts
val alice = Account.generate()val bob = Account.generate()aptos.fundAccount(accountAddress = alice.accountAddress, amount = 100_000_000L).expect("Failed to fund Alice")aptos.fundAccount(accountAddress = bob.accountAddress, amount = 100_000_000L).expect("Failed to fund Bob")For single-key and multi-key account patterns, see Accounts.
-
Build and send a transaction
The lean transaction builder uses
typeArgs(...)andargs(...).val pendingTxn =aptos.execute(signer = alice) {function = "0x1::coin::transfer"typeArgs("0x1::aptos_coin::AptosCoin")args(bob.accountAddress, 1_000_000UL)}.expect("Failed to build/sign/submit transaction") -
Wait for confirmation
val executedTxn =aptos.waitForTransaction(HexInput.fromString(pendingTxn.hash)).expect("Transaction did not execute successfully")println("Executed transaction version: ${executedTxn.version}")
Need finer control (separate build/sign/submit, fee-payer flow, simulation)? See Building Transactions.