Android Integration Guide
Last updated
Was this helpful?
Was this helpful?
dependencies {
implementation "com.trustwallet:wallet-core:<latest_tag>"
}
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/trustwallet/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")
}
}
}
}init {
System.loadLibrary("TrustWalletCore")
}val wallet = HDWallet(128, "")val wallet = HDWallet("ripple scissors kick mammal hire column oak again sun offer wealth tomorrow wagon turn fatal", "")val addressBTC = wallet.getAddressForCoin(CoinType.BITCOIN)
val addressETH = wallet.getAddressForCoin(CoinType.ETHEREUM)val key = wallet.getKey(CoinType.ETHEREUM, "m/44\'/60\'/1\'/0/0") // m/44'/60'/1'/0/0
val address = CoinType.ETHEREUM.deriveAddress(key)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${output.encoded.toByteArray().toHexString()}")