跳转到内容

Kotlin SDK Quickstart

此内容尚不支持你的语言。

This quickstart gets you from dependency setup to a confirmed transaction using the current Kaptos API shape.

  1. Install the SDK

    Kaptos publishes multiplatform and platform-specific artifacts to Maven Central.

    kotlin {
    sourceSets {
    commonMain.dependencies {
    implementation("xyz.mcxross.kaptos:kaptos:<version>")
    }
    }
    }
    dependencies {
    implementation("xyz.mcxross.kaptos:kaptos-jvm:<version>")
    }
  2. Configure the client

    val aptos = Aptos(
    AptosConfig(
    settings = AptosSettings(
    network = Network.DEVNET,
    clientConfig = ClientConfig(maxRetries = 10),
    )
    )
    )
  3. 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")
  4. 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.

  5. Build and send a transaction

    The lean transaction builder uses typeArgs(...) and args(...).

    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")
  6. 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.