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 generateSignRequest({
uuid,
signData,
path,
fee,
xfp,
origin,
}: {
uuid: string;
signData: string;
path: string;
fee?: number;
xfp: string;
origin?: string;
}): UR;
static parseSignature(ur: UR): Record<string, any>;
}
generateSignRequest
static generateSignRequest({
uuid,
signData,
path,
fee,
xfp,
origin,
}: {
uuid: string;
signData: string;
path: string;
fee?: number;
xfp: string;
origin?: string;
}): UR;
Input Parameters
-
uuid:
StringrequiredRepresenting 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 parseSignature(ur: UR): Record<string, any>;
Returns
-
uuid:
Uint8Listtransaction ID. -
signature:
Stringsignature of transaction. -
origin:
Stringusually "GsWallet".
Example
Construct transaction && Parse signature
import { GsWalletTronSDK } from "gs-ur-js";
export const Tron = () => {
const [isScanning, setIsScanning] = useState(false);
const [tronSignedData, settronSignedData] = useState(null);
const ur = GsWalletTronSDK.generateSignRequest(
uuid: "cf6645a0-8d24-11ef-90ac-6dae386eaee6",
signData:
"0a02c5fc2208a02f893e39e02b5840e8c38692ec315a68080112640a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412330a1541ac28610814b8b72e308dbb822c388400ad4aa2ef12154128ff40a1e26781937ba6f700a20daa74e6ef548e1880dac40970b5888392ec31",
path: "m/44'/195'/0'/0/0",
xfp: "27c3831f",
origin: null,
fee: 0);
const onSucceed = ({type, cbor}) => {
const trxSignature = GsWalletTronSDK.parseSignature(new UR(Buffer.from(cbor, "hex"), type))
console.log("tronSigned: ", trxSignature);
settronSignedData(trxSignature);
setIsScanning(false);
}
const onError = (errorMessage) => {
console.log("error: ",errorMessage);
settronSignedData(null);
setIsScanning(false);
}
return (
<div style={{ display: 'flex', alignItems: 'center' }}> {/* Use flexbox for layout */}
{isScanning ? (
<AnimatedQRScanner
handleScan={onSucceed}
handleError={onError}
urTypes={[URType.TronSignature]}
options={{ width: 400, height: 300 }}
/>
) : (
<>
<AnimatedQRCode type={ur.type} cbor={ur.cbor.toString("hex")} />
<button style={{marginLeft: '20px'}} onClick={() => setIsScanning(true)}>Scan GsWallet</button>
{tronSignedData && ( // Conditionally render the box
<div style={{
marginLeft: '20px', // Add some spacing
border: '1px solid #ccc',
padding: '10px',
backgroundColor: '#f9f9f9'
}}>
<h3>tronSigned Data:</h3>
<pre>{tronSignedData}</pre> {/* Display tronSigned directly */}
</div>
)}
{tronSignedData === null && <div style={{marginLeft: '40px'}}>Waiting for scan...</div>}
</>
)}
</div>
);
}
// tronSigned: {
// "uuid": [207,102,69,160,141,36,17,239,144,172,109,174,56,110,174,230],
// "signature":"e07b32499c85a312fd86a8c0f775a0bce723a14336f71e8f6596a28a15bbf79801338e57f3fb18ca75db58977682062c29853b390966baf9303680edf548e01f01",
// "origin":"GSWALLET",
// };