首页 > 解决方案 > 安卓应用程序中的 Tron 钱包集成

问题描述

我正在为 TRON 区块链开发一个安卓应用程序。我正在使用 Trust 钱包库。

implementation 'com.trustwallet:wallet-core:2.3.9'

签署交易几乎完成,但广播我需要raw_data_hex 数据。我怎样才能得到它。

代码

 val privateStr = "privatekey"
 val privateBytes: ByteArray = fromHexString(privateStr)
 val trc = Tron.TransferContract.newBuilder()
           .setOwnerAddress("owner_address")
           .setToAddress("toadress")
           .setAmount(1000000L)
 val transaction = Tron.Transaction.newBuilder()
                    .setTransfer(trc)
                    .build()

 val signingInput = Tron.SigningInput.newBuilder()
                    .setTransaction(transaction)
                    .setPrivateKey(ByteString.copyFrom(privateBytes))
 val output = AnySigner.sign(signingInput.build(), CoinType.TRON, Tron.SigningOutput.parser())
 println("*****signing_output${output.json}")

输出 json 是

{"raw_data":{"contract":[{"parameter":{"type_url":"type.googleapis.com/protocol.TransferContract","value":{"amount":1000000,"owner_address":"419c84ec90ef46e68530893cf3229a1dd695b8b457","to_address":"41105e58ce5d754034475f24149ab910f9602bc141"}},"type":"TransferContract"}],"expiration":1608078105411,"ref_block_bytes":"0000","ref_block_hash":"9afbf4c8996fb924","timestamp":1608042105411},"signature":["7204dd578e610164d415f30e57eeb07cab2028a82992c6986f932271796d14b810f85e7b634e0606eefcfe9c76a85663f68a076be8efe7f2355fdb2dc5986f2801"],"txID":"6f3027995c380950442a0f9479ccf31948c7d1134314e333d4b3688799f3d4d1"}

标签: androidcryptocurrencytrusttron

解决方案


推荐阅读