TRON API
The TronApp class provides TRON address retrieval,
transaction signing, and message signing. It uses the same INS codes as
Ethereum, but coin_type=195' in the BIP44 path puts the
firmware into TRON mode.
Key Differences from
Ethereum
| Aspect |
Ethereum |
TRON |
| Address format |
0x... (hex) |
T... (Base58Check) |
| TX hash |
Keccak-256 |
SHA-256 |
| Signature response |
V(1) + R(32) + S(32) |
R(32) + S(32) + V(1) |
| V value |
27 or 28 |
0 or 1 (recovery ID) |
Import
import {
TronApp,
DEFAULT_TRON_PATH,
type SignatureResult,
} from '@openloop/sdk-core'
Initialization
const tron = new TronApp(transport)
Methods
| Method |
Description |
getAddress(path) |
Get the TRON address (T...) and the public key |
signTransaction(path, rawDataHex) |
Sign the raw_data of a transaction |
signMessage(path, message) |
Sign a message |
getAddress
Get the TRON address — Base58Check format, T... — from
the device.
async getAddress(path: string): Promise<{
publicKey: string // Uncompressed public key (hex, 65 bytes)
address: string // Base58Check address ("T...")
}>
Parameters
| Name |
Type |
Description |
path |
string |
BIP44 path (e.g. "44'/195'/0'/0/0") |
Default Path
DEFAULT_TRON_PATH = "44'/195'/0'/0/0"
Example
const { address } = await tron.getAddress(DEFAULT_TRON_PATH)
// address: "TLsV62...txnV1Fm"
signTransaction
Sign the raw_data of a TRON transaction.
async signTransaction(
path: string,
rawDataHex: string
): Promise<SignatureResult>
Parameters
| Name |
Type |
Description |
path |
string |
BIP44 path |
rawDataHex |
string |
Hex of the protobuf-encoded raw_data (with or without
0x) |
Returns:
SignatureResult
| Field |
Type |
Description |
v |
number |
Recovery ID (0 or 1) |
r |
string |
R value (32 bytes hex) |
s |
string |
S value (32 bytes hex) |
Example
const sig = await tron.signTransaction(
DEFAULT_TRON_PATH,
'a1b2c3d4...' // raw_data hex
)
signMessage
Sign a TRON message. The firmware reads coin_type=195'
from the BIP44 path and applies the TRON message format.
async signMessage(
path: string,
message: string
): Promise<SignatureResult>
Parameters
| Name |
Type |
Description |
path |
string |
BIP44 path |
message |
string |
UTF-8 message string |
Example
const sig = await tron.signMessage(DEFAULT_TRON_PATH, 'Hello, TRON!')
TronWeb Integration
import TronWeb from 'tronweb'
import { TronApp, DEFAULT_TRON_PATH } from '@openloop/sdk-core'
import { WebHidTransport } from '@openloop/transport-webhid'
const transport = await WebHidTransport.connect()
const tron = new TronApp(transport)
// Get the address
const { address } = await tron.getAddress(DEFAULT_TRON_PATH)
// Build the transaction with TronWeb
const tronWeb = new TronWeb({ fullHost: 'https://api.trongrid.io' })
const transaction = await tronWeb.transactionBuilder.sendTrx(
'TLsV62...', // Recipient
1000000, // 1 TRX = 1,000,000 SUN
address
)
// Convert raw_data to hex and sign on the device
const rawDataHex = Buffer.from(
JSON.stringify(transaction.raw_data)
).toString('hex')
const sig = await tron.signTransaction(DEFAULT_TRON_PATH, rawDataHex)
// Add the signature to the transaction
const signedTx = {
...transaction,
signature: [`${sig.r}${sig.s}0${sig.v}`],
}
// Broadcast
const result = await tronWeb.trx.sendRawTransaction(signedTx)
Next Steps