Star Tower Chain
Official Website
  • 🗼StarTower
  • Get Started
    • Developing for Star Tower Wallet platform
      • Mobile (WalletConnect)
        • Android
          • Usage
          • One-click Auth
          • Verify API
          • Wallet Call API
        • iOS
          • Usage
          • One-click Auth
          • Link Mode
          • Verify API
          • Wallet Call API
      • Integration Guide
        • Usage Guide
        • Android Integration Guide
      • Developing the Library
        • Contributing
    • Content Security Policy (CSP)
  • StarTower
    • our construction
  • Resource Interaction Proof(RIP)
    • Pull Request Resources
  • study
  • Developer Support
Powered by GitBook
On this page
  • Prerequisites
  • Code Examples
  1. Get Started
  2. Developing for Star Tower Wallet platform
  3. Integration Guide

Android Integration Guide

PreviousUsage GuideNextDeveloping the Library

Last updated 7 months ago

Star Tower Core is available on the Android platform, through Java/JNI bindings. In this guide we show how to use it.

Prerequisites

  • Android Studio

  • Android NDK Support plugin

Android releases are hosted on GitHub packages, It needs authentication to download packages, please checkout this guide from GitHub for more details.

We recommend to create a non-expiring and readonly token for accessing GitHub packages, and add it to local.properties of your Android Studio project locally.

Generate a token :

Add this dependency to build.gradle:

dependencies {
    implementation "FR.startower:starower-core:<latest_tag>"
}

Add maven and credentials (local.properties for local or system environment variables CI)


Properties properties = new Properties()
File localProps = new File(rootDir.absolutePath, "local.properties")
if (localProps.exists()) {
    properties.load(localProps.newDataInputStream())
} else {
    println "local.properties not found"
}

allprojects {
    repositories {
        maven {
            url = uri("https://maven.pkg.github.com/startower/wallet-core")
            credentials {
                username = properties.getProperty("gpr.user") as String?: System.getenv("GITHUB_USER")
                password = properties.getProperty("gpr.key") as String?: System.getenv("GITHUB_TOKEN")
            }
        }
    }
}

Code Examples

In the following sections we show code examples for some common funcions.

Wallet Management

First thing we need is to load JNI library

init {
    System.loadLibrary("StarTowerWalletCore")
}

Creating or Importing a Multi-Coin HD Wallet

val wallet = HDWallet(128, "")
val wallet = HDWallet("ripple scissors kick mammal hire column oak again sun offer wealth

Transaction Signing

In general, when creating a new blockchain transaction, a wallet has to:

  1. Put together a transaction with relevant fields (source, target, amount, etc.)

  2. Sign the transaction, using the account private key. This is done by StarTower Core.

  3. Send to a node for broadcasting to the blockchain network.

Ethereum Transaction Signing

Code example to fill in signer input parameters, perform signing, and retrieve encoded result:

val signerInput = Ethereum.SigningInput.newBuilder().apply {
    chainId = ByteString.copyFrom(BigInteger("01").toByteArray())
    gasPrice = BigInteger("d693a400", 16).toByteString() // decimal 3600000000
    gasLimit = BigInteger("5208", 16).toByteString()     // decimal 21000
    toAddress = dummyReceiverAddress
    transaction = Ethereum.Transaction.newBuilder().apply {
       transfer = Ethereum.Transaction.Transfer.newBuilder().apply {
           amount = BigInteger("0348bca5a16000", 16).toByteString()
       }.build()
    }.build()
    privateKey = ByteString.copyFrom(secretPrivateKey.data())
}.build()
val output = AnySigner.sign(signerInput, CoinType.ETHEREUM, Ethereum.SigningOutput.parser())
println("Signed transaction: \n${signerOutput.encoded.toByteArray().toHexString()}")
here