Registry / blockchain / tron-grpc

tron-grpc

JSON →
library1.0.1jsnpmunverified

A fully-typed TypeScript client for the TRON blockchain that communicates with java-tron full nodes over gRPC. Version 1.0.1 provides a high-level API abstracting away protobuf encoding, base58↔hex address conversion, and sun-to-TRX amount conversion. It requires Node.js 20+ (uses built-in fetch and TextEncoder) and is developed by TronSave/SaveWallet. Compared to alternatives like tronweb or tronbox, tron-grpc is ESM-only, has zero non-peer runtime dependencies, and outputs human-readable strings instead of raw buffers.

npm install tron-grpc
INSTALL
IMPORT
SIG · TRON-GRPC
T
tron-grpc
blockchainjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TronGrpcClient
import { TronGrpcClient } from 'tron-grpc'
const TronGrpcClient = require('tron-grpc').TronGrpcClient
This package is ESM-only; require() will throw. Use named import.
BlockSummary
import { BlockSummary } from 'tron-grpc'
TypeScript types are exported for convenience, but must be imported explicitly.
default
import TronGrpcClient from 'tron-grpc'
Default import is also available (same as named import). Not recommended for clarity.

Creates a mainnet client, fetches the latest block, queries an account's TRX and USDT balances, then closes the client.

import { TronGrpcClient } from 'tron-grpc'; const client = TronGrpcClient.fromNetwork('mainnet', { headers: { 'TRON-PRO-API-KEY': process.env.TRON_PRO_API_KEY ?? '' }, }); async function main() { const head = await client.getNowBlock(); console.log(head.number, head.hash); const account = await client.getAccount('TWd4WrZ9wn84f5x1hZhL4DHvk738ns5jwb'); console.log(account.balanceTrx); const usdt = await client.getTrc20Balance( 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', 'TWd4WrZ9wn84f5x1hZhL4DHvk738ns5jwb', ); console.log(usdt.value); client.close(); } main().catch(console.error);
Debug
Known issues
breakingNode.js 20+ required. Older Node versions lack global fetch and TextEncoder.
fix
Upgrade Node.js to version 20 or later.
affects: <20.0.0
gotchaThe client uses gRPC with a keepalive of 30 seconds by default. Ensure network policies allow outbound gRPC traffic on port 50051.
fix
Adjust grpcOptions or firewall settings if connection drops unexpectedly.
affects: >=1.0.0
deprecatedgetBalance() returns balance as string. Use getAccount().balanceTrx instead for consistency.
fix
Replace getBalance(address) with getAccount(address) then access .balanceTrx.
affects: >=1.0.0
gotchaAddresses can be base58 or hex. Hex addresses must start with '41' or '0x41'. Inconsistent prefix usage may cause silent failures.
fix
Ensure hex addresses start with '41' or '0x41'. If you have '0x' prefix with other bytes, convert to base58 or pad as needed.
affects: >=1.0.0
breakingESM-only package. Usage with require() (CommonJS) throws a runtime error.
fix
Use import syntax or dynamic import() in your project. If you must use require, upgrade your project to ESM (e.g., set type: module in package.json).
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module /path/to/node_modules/tron-grpc/... not supported
tron-grpc is ESM-only but imported via CommonJS require().
fix
Use import { TronGrpcClient } from 'tron-grpc' instead of require().
TypeError: fetch is not a function
Node.js version older than 18 (or 20 if TextEncoder not global). The library uses fetch internally.
fix
Upgrade Node.js to version 20 or later.
Error: 14 UNAVAILABLE: failed to connect to all addresses; last error: ...
gRPC cannot connect to the TRON node (wrong URL, firewall, or node down).
fix
Check the node URL (e.g., 'grpc.trongrid.io:50051'), network connectivity, and API key if required.
TypeError: Cannot read properties of undefined (reading 'balanceTrx')
getAccount() returned undefined or the account does not exist (balance field missing).
fix
Check if the address is valid and activated. Use account.exists field to verify presence before accessing balanceTrx.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
@grpc/grpc-jsrequiredpeer dependency for gRPC client communication
Agent activity
39 hits · last 30 days
node
34
OpenAI (training)
1
Resources
tron-grpc — npm install tron-grpc · libregistry