UNPKG

@ledgerhq/coin-tron

Version:
36 lines 1.86 kB
import BigNumber from "bignumber.js"; export declare const abiEncodeTrc20Transfer: (address: string, amount: BigNumber) => string; export type Trc20TransferData = { to: string; amount: BigNumber; }; /** * Decodes ABI-encoded TRC20 transfer call data into recipient address and amount. * * TRC20 transfer calls follow the Ethereum ABI encoding specification: * - Bytes 0-3 (4 bytes / 8 hex chars): Function selector "a9059cbb" for transfer(address,uint256) * - Bytes 4-35 (32 bytes / 64 hex chars): Recipient address, left-padded to 32 bytes * - Bytes 36-67 (32 bytes / 64 hex chars): Transfer amount as uint256, left-padded to 32 bytes * * TRON address encoding: * Unlike standard EVM (20-byte addresses), TRON encodes addresses with the "41" prefix included, * making them 21 bytes. The 32-byte ABI slot contains: * - 11 bytes (22 hex chars) of zero padding * - 21 bytes (42 hex chars) = "41" prefix + 20-byte address * * Example encoded data from TRON transactions: * ``` * a9059cbb <- selector (8 chars) * 000000000000000000000041ec20315a879c48f5e3a6a1c9826d5225f8b658b8 <- address (64 chars, 21-byte TRON addr) * 00000000000000000000000000000000000000000000000000000000027bf24d <- amount (64 chars) * ``` * * The slice(24) logic skips 12 bytes (24 hex chars), which removes both the zero padding (11 bytes) * AND the "41" prefix byte. We then prepend "41" back to produce a valid TRON hex address. * * @param data - Hex-encoded call data, optionally prefixed with "0x" * @returns Decoded transfer data with TRON-format recipient address (41 + 20 bytes) and amount, or null if invalid */ export declare const abiDecodeTrc20Transfer: (data: string) => Trc20TransferData | null; export declare const hexToAscii: (hex: string) => string; //# sourceMappingURL=utils.d.ts.map