TronWallet is an Android toolbelt for interaction with the Tron network.
For more specific usage, please refer to the demo
I strongly recommend https://jitpack.io
repositories {
...
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.james19870606:TronWallet:1.0.7'
}
val onCompleted = {result : Boolean,error : String ->
//......
}
val privateKey = ""
val node = if(position == 0) TRONMainNet else TRONNileNet
if (tronweb?.isGenerateTronWebInstanceSuccess == false) {
tronweb?.setup(true, privateKey, node = node,onCompleted = onCompleted)
} else {
}
val onCompleted = {state: Boolean, address: String, privateKey: String, publicKey: String, mnemonic: String, error: String ->
runOnUiThread {
val text = """
address: $address
mnemonic: $mnemonic
privateKey: $privateKey
publicKey: $publicKey
"""
walletDetail?.setText(if (state) text else error)
}
}
tronweb?.createRandom(onCompleted = onCompleted)
val onCompleted = { state: Boolean, hexAddress: String, base58Address: String, privateKey: String, publicKey: String, error: String ->
runOnUiThread {
val text = """
hexAddress: $hexAddress
base58Address: $base58Address
privateKey: $privateKey
publicKey: $publicKey
"""
walletDetail?.setText(if (state) text else error)
}
}
tronweb?.createAccount(onCompleted = onCompleted)
val mnemonic = mnemonicEditText?.getText().toString();
val onCompleted = { state: Boolean, address: String, privateKey: String, publicKey: String, error: String ->
runOnUiThread {
val text = """
address: $address
privateKey: $privateKey
publicKey: $publicKey
"""
walletDetail?.setText(if (state) text else error)
}
}
tronweb?.importAccountFromMnemonic(mnemonic, onCompleted = onCompleted)
val onCompleted = {state : Boolean, txid: String ,error:String->
this.runOnUiThread {
if (state){
hashValue?.text = txid
} else {
hashValue?.text = error
}
}
}
tronweb?.trxTransferWithOutRemark(
toAddress ,
amount ,
onCompleted = onCompleted)
val onCompleted = {state : Boolean, txid: String,error:String ->
this.runOnUiThread {
if (state){
hashValue?.text = txid
} else {
hashValue?.text = error
}
}
}
tronweb?.trc20TokenTransfer(
toAddress,
trc20ContractAddress,
amount,
remark,
onCompleted = onCompleted)
更详细的使用方法,建议参考 demo
TronWeb is released under the MIT license. See LICENSE for details.