npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dynamic-labs/tron

v4.50.3

Published

A React SDK for implementing wallet web3 authentication and authorization to your website.

Downloads

3,772

Readme

@dynamic-labs/tron

Tron blockchain integration for the Dynamic SDK using the industry-standard TronWallet Adapter.

Overview

This package provides seamless integration with Tron wallets in your dApp using the TronWallet Adapter standard. By leveraging the TronWallet Adapter, you get access to 9+ Tron wallets through a single, unified interface with automatic wallet detection, connection management, and standardized transaction handling.

Installation

npm install @dynamic-labs/tron

Supported Wallets

This package supports the following Tron wallets through TronWallet Adapter:

| Wallet | Type | Description | | ----------------- | ----------------- | ------------------------------------ | | OKX Wallet | Browser Extension | Multi-chain wallet with Tron support | | Bitget Wallet | Browser Extension | Formerly BitKeep | | TokenPocket | Mobile/Extension | Multi-chain wallet | | Trust Wallet | Mobile/Extension | Popular multi-chain wallet |

Usage

Basic Integration

Integrate all Tron wallets into your Dynamic configuration:

import { DynamicContextProvider } from '@dynamic-labs/sdk-react-core';
import { TronWalletConnectors } from '@dynamic-labs/tron';

function App() {
  return (
    <DynamicContextProvider
      settings={{
        environmentId: 'your-environment-id',
        walletConnectors: [TronWalletConnectors()],
      }}
    >
      {/* Your app content */}
    </DynamicContextProvider>
  );
}

Working with Tron Wallets

Use the isTronWallet type guard to safely access Tron-specific functionality:

import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isTronWallet } from '@dynamic-labs/tron';

function MyComponent() {
  const { primaryWallet } = useDynamicContext();

  const handleSendTrx = async () => {
    if (!isTronWallet(primaryWallet)) {
      console.error('Not a Tron wallet');
      return;
    }

    try {
      // Send 10 TRX
      const result = await primaryWallet.sendTrx('TRecipientAddress...', 10);
      console.log('Transaction sent:', result.txid);
    } catch (error) {
      console.error('Transaction failed:', error);
    }
  };

  return <button onClick={handleSendTrx}>Send TRX</button>;
}

Accessing TronWeb

Get direct access to the TronWeb instance:

import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isTronWallet } from '@dynamic-labs/tron';

function MyComponent() {
  const { primaryWallet } = useDynamicContext();

  const getTronWebInstance = () => {
    if (!isTronWallet(primaryWallet)) return null;

    const tronWeb = primaryWallet.getTronWeb();
    return tronWeb;
  };

  const checkBalance = async () => {
    const tronWeb = getTronWebInstance();
    if (!tronWeb) return;

    const balance = await tronWeb.trx.getBalance(primaryWallet.address);
    console.log('Balance (in SUN):', balance);
    console.log('Balance (in TRX):', balance / 1_000_000);
  };

  return <button onClick={checkBalance}>Check Balance</button>;
}

Signing Messages

Sign messages with Tron wallets (uses signMessageV2):

import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isTronWallet } from '@dynamic-labs/tron';

function MyComponent() {
  const { primaryWallet } = useDynamicContext();

  const handleSignMessage = async () => {
    if (!isTronWallet(primaryWallet)) return;

    try {
      const message = 'Hello, Tron!';
      const signature = await primaryWallet.signMessage(message);
      console.log('Signature:', signature);

      // Verify the signature
      const tronWeb = primaryWallet.getTronWeb();
      if (tronWeb) {
        const recoveredAddress = await tronWeb.trx.verifyMessageV2(
          message,
          signature,
        );
        console.log('Verified:', recoveredAddress === primaryWallet.address);
      }
    } catch (error) {
      console.error('Signing failed:', error);
    }
  };

  return <button onClick={handleSignMessage}>Sign Message</button>;
}

Working with TRC20 Tokens

Get token balances and interact with TRC20 tokens:

import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isTronWallet } from '@dynamic-labs/tron';

function MyComponent() {
  const { primaryWallet } = useDynamicContext();

  const getUSDTBalance = async () => {
    if (!isTronWallet(primaryWallet)) return;

    // USDT contract address on Tron mainnet
    const usdtContract = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';

    try {
      const balance = await primaryWallet.getTokenBalance(usdtContract);
      console.log('USDT Balance:', balance);
    } catch (error) {
      console.error('Failed to get token balance:', error);
    }
  };

  return <button onClick={getUSDTBalance}>Get USDT Balance</button>;
}

Network Information

Get current network details:

import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isTronWallet } from '@dynamic-labs/tron';

function MyComponent() {
  const { primaryWallet } = useDynamicContext();

  const getNetworkInfo = async () => {
    if (!isTronWallet(primaryWallet)) return;

    const network = await primaryWallet.getNetworkDetails();
    console.log('Chain ID:', network.chainId);
    console.log('Network Name:', network.name);
  };

  return <button onClick={getNetworkInfo}>Get Network Info</button>;
}

Supported Networks

The package includes built-in support for:

  • Tron Mainnet (Chain ID: 0x2b6653dc)
  • Nile Testnet (Chain ID: 0x94a9059e)
  • Shasta Testnet (Chain ID: 0x401e93ff)

Custom Networks

You can configure custom networks when creating connectors:

import { TronLinkConnector } from '@dynamic-labs/tron';
import type { GenericNetwork } from '@dynamic-labs/types';

const customNetworks: GenericNetwork[] = [
  {
    blockExplorerUrls: ['https://custom-explorer.com'],
    chainId: '0x12345678',
    chainName: 'Custom Tron Network',
    name: 'Custom Tron Network',
    nativeCurrency: {
      decimals: 6,
      name: 'TRX',
      symbol: 'TRX',
    },
    networkId: '0x12345678',
    rpcUrls: ['https://custom-rpc.example.com'],
    vanityName: 'Custom Network',
  },
];

// Use with connector
const connector = new TronLinkConnector({
  walletBook: walletBookInstance,
  tronNetworks: customNetworks,
});

API Reference

TronWallet Class

The main wallet class for Tron wallets.

Methods

  • getAddress(): Promise<string> - Get the wallet address
  • getNetwork(): Promise<string | number | undefined> - Get current network
  • signMessage(message: string | Uint8Array): Promise<string> - Sign a message
  • getBalance(address?: string): Promise<string | undefined> - Get TRX balance
  • sendTrx(to: string, amount: number, options?: { from?: string }): Promise<BroadcastReturn> - Send TRX
  • getTokenBalance(tokenId: string, address?: string): Promise<number> - Get TRC20 token balance
  • getNetworkDetails(): Promise<{ chainId: string; name: string }> - Get network info
  • getTronWeb(): TronWeb | undefined - Get TronWeb instance

isTronWallet()

Type guard to check if a wallet is a Tron wallet.

function isTronWallet(wallet: Wallet | null | undefined): wallet is TronWallet;

Architecture

This package uses the TronWallet Adapter pattern, which provides:

  1. Adapter Layer: Each wallet connector wraps a TronWallet Adapter instance
  2. Unified Interface: All wallets expose the same methods and events
  3. Event Handling: Standardized events for connect, disconnect, account changes, etc.
  4. Network Detection: Automatic network detection and switching support

The architecture follows Dynamic's wallet connector pattern while leveraging the TronWallet Adapter's battle-tested implementations.

Development

Build

npx nx build tron

Test

npx nx test tron

Lint

npx nx lint tron

TypeScript Support

This package is written in TypeScript and provides full type definitions. Enable strict mode in your tsconfig.json for the best experience:

{
  "compilerOptions": {
    "strict": true
  }
}

Resources

  • TronWallet Adapter Docs: https://walletadapter.org/docs/
  • Dynamic Docs: https://docs.dynamic.xyz
  • TronWeb Docs: https://developers.tron.network/docs
  • Tron Network: https://tron.network

Support

License

This package is part of the Dynamic SDK and follows the same licensing terms. See LICENSE for details


Built with ❤️ by the Dynamic Labs team