Trust Developer
Search…
Android Integration Guide
Wallet 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

Adding Library Dependency

Add this dependency to build.gradle:
1
dependencies {
2
implementation "com.trustwallet:wallet-core:0.12.31"
3
}
Copied!

Code Examples

In the following sections we show code examples for some common funcions. Please refer to the Wallet Usage Guide for detailed explanations.

Wallet Management

First thing we need is to load JNI library
1
init {
2
System.loadLibrary("TrustWalletCore")
3
}
Copied!
Creating or Importing a Multi-Coin HD Wallet
1
val wallet = HDWallet(128, "")
Copied!
1
val wallet = HDWallet("ripple scissors kick mammal hire column oak again sun offer wealth tomorrow wagon turn fatal", "")
Copied!

Account Address Derivation

Generating the Default Address for a Coin
1
val addressBTC = wallet.getAddressForCoin(CoinType.BITCOIN)
2
val addressETH = wallet.getAddressForCoin(CoinType.ETHEREUM)
3
val addressBNB = wallet.getAddressForCoin(CoinType.BINANCE)
Copied!
Generating an Address Using a Custom Derivation Path (Expert)
1
val key = wallet.getKey("m/44\'/60\'/1\'/0/0") // m/44'/60'/1'/0/0
2
val address = CoinType.ETHEREUM.deriveAddress(key)
Copied!

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 Wallet 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:
1
val signerInput = Ethereum.SigningInput.newBuilder().apply {
2
this.chainId = ByteString.copyFrom(BigInteger("01").toByteArray())
3
this.gasPrice = BigInteger("d693a400", 16).toByteString() // decimal 3600000000
4
this.gasLimit = BigInteger("5208", 16).toByteString() // decimal 21000
5
this.toAddress = dummyReceiverAddress
6
this.transaction = Ethereum.Transaction.newBuilder().apply {
7
this.transfer = Ethereum.Transaction.Transfer.newBuilder().apply {
8
this.amount = BigInteger("0348bca5a16000", 16).toByteString()
9
}.build()
10
}.build()
11
this.privateKey = ByteString.copyFrom(secretPrivateKey.data())
12
}.build()
13
val output = AnySigner.sign(signerInput, CoinType.ETHEREUM, Ethereum.SigningOutput.parser())
14
println("Signed transaction: \n${signerOutput.encoded.toByteArray().toHexString()}")
Copied!
Last modified 2mo ago