TRON
This article describes the process of completing a Tron transaction through the SDK.
Support List
Support most TRX-series cryptocurrencies and their tokens.
- Tron
GsWalletTronSDK
The GsWalletTronSDK class mainly implements the following functions:
- Construct TRX transactions.
- Parse signature information.
class GsWalletTronSDK {
static UR generateSignRequest({
String? uuid,
required String signData,
required String path,
int? fee,
required String xfp,
String? origin,
});
static Map<String, dynamic> parseSignature(UR ur);
}
generateSignRequest
static UR generateSignRequest({
String? uuid,
required String signData,
required String path,
int? fee,
required String xfp,
String? origin,
});
Input Parameters
-
uuid:
StringoptionalRepresenting the unique ID of a transaction -
signData:
StringrequiredUnsigned-transaction data, it's serialized hex for a TRX transaction -
path:
StringrequiredBIP32 derivation path for from-address of the transaction -
xfp:
StringrequiredMasterFingerprint, used as a unique wallet ID -
origin:
StringoptionalNotes for transaction, usually source of the request -
fee:
intoptionalTransaction fee, minimum unit.
parseSignature
static Map<String, dynamic> parseSignature(UR ur);
Returns
-
uuid:
Uint8Listtransaction ID. -
signature:
Stringsignature of transaction. -
origin:
Stringusually "GsWallet".
Example
Construct transaction
import 'package:gs_ur_dart/gs_ur_dart.dart';
UR ur = GsWalletTronSDK.generateSignRequest(
uuid: "cf6645a0-8d24-11ef-90ac-6dae386eaee6",
signData:
"0a02c5fc2208a02f893e39e02b5840e8c38692ec315a68080112640a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412330a1541ac28610814b8b72e308dbb822c388400ad4aa2ef12154128ff40a1e26781937ba6f700a20daa74e6ef548e1880dac40970b5888392ec31",
path: "m/44'/195'/0'/0/0",
xfp: "27c3831f",
origin: null,
fee: 0);
final UREncoder urEncoder = UREncoder(ur);
String _currentQR = urEncoder.nextPart();
emit(_AnimatedQRDataState(_currentQR));
timer = Timer.periodic(const Duration(milliseconds: 250), (_) {
_currentQR = urEncoder.nextPart();
emit(_AnimatedQRDataState(_currentQR));
});
Parse signature
import 'package:gs_ur_dart/gs_ur_dart.dart';
typedef SuccessCallback = void Function(UR);
final SuccessCallback onSuccess;
final QRViewController controller;
controller.scannedDataStream.listen((event) {
URDecoder urDecoder = URDecoder();
urDecoder.receivePart(event.code);
double progress = urDecoder.getProgress();
if (urDecoder.isComplete()) {
final UR result = urDecoder.resultUR();
if (!succeed) {
onSuccess(result);
succeed = true;
}
}
});
onSuccess(UR ur){
final tronSigned = GsWalletTronSDK.parseSignature(ur);
}
// tronSigned: {
// "uuid": [207,102,69,160,141,36,17,239,144,172,109,174,56,110,174,230],
// "signature":"e07b32499c85a312fd86a8c0f775a0bce723a14336f71e8f6596a28a15bbf79801338e57f3fb18ca75db58977682062c29853b390966baf9303680edf548e01f01",
// "origin":"GSWALLET",
// };