Skip to main content
Dynamic offers full Tron wallet support through the @dynamic-labs/tron package, enabling seamless integration with Tron network wallets using the industry-standard TronWallet Adapter. This provides access to 9+ Tron wallets through a single, unified interface.

Installation

First, install the Tron wallet connector package:
npm install @dynamic-labs/tron

Supported Wallets

This package supports the following Tron wallets through TronWallet Adapter:
WalletTypeDescription
OKX WalletBrowser ExtensionMulti-chain wallet with Tron support
Bitget WalletBrowser ExtensionFormerly BitKeep
TokenPocketMobile/ExtensionMulti-chain wallet
Trust WalletMobile/ExtensionPopular multi-chain wallet

Supported Networks

NetworkChain IDDescriptionBlock Explorer
Tron Mainnet728126428Production networkTronscan
Shasta Testnet728126429Test networkShasta Tronscan
Nile Testnet728126430Test networkNile Tronscan

Basic Integration

To use Tron wallets in your app, add the Tron wallet connectors to your Dynamic configuration:
  • React
  • React Native
React
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>
  );
}

Check if a wallet is a Tron wallet

The first thing you should do is check if the wallet is a Tron wallet. You can use the isTronWallet helper method for that. That way, TypeScript will know which methods etc. are available to you.
  • React
  • React Native
React
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isTronWallet } from '@dynamic-labs/tron';

const { wallet } = useDynamicContext();

if (!isTronWallet(wallet)) {
  throw new Error('This wallet is not a Tron wallet');
}

Fetch the wallet address

You can get the wallet address using the wallet.address property:
  • React
  • React Native
React
const { primaryWallet } = useDynamicContext();

const tronAddress = primaryWallet.address;

Send TRX

To send TRX (the native Tron currency) to another address, use the sendTrx method:
  • React
  • React Native
React
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isTronWallet } from '@dynamic-labs/tron';

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);
  }
};

Send TRC20 Tokens

To send TRC20 tokens (like USDT) to another address, use the sendTrc20 method:
  • React
  • React Native
React
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isTronWallet } from '@dynamic-labs/tron';

const { primaryWallet } = useDynamicContext();

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

  try {
    // USDT contract address on Tron mainnet
    const usdtContract = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';
    
    // Send 100 USDT (assuming 6 decimals)
    const result = await primaryWallet.sendTrc20({
      amount: '100',
      toAddress: 'TRecipientAddress...',
      token: {
        address: usdtContract,
        decimals: 6,
      },
    });
    console.log('Transaction sent:', result);
  } catch (error) {
    console.error('Transaction failed:', error);
  }
};

Sign Messages

Tron wallets support message signing for authentication using signMessageV2:
  • React
  • React Native
React
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isTronWallet } from '@dynamic-labs/tron';

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);
  }
};

Get Balance

To get the TRX balance of an address, use the getBalance method:
  • React
  • React Native
React
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isTronWallet } from '@dynamic-labs/tron';

const { primaryWallet } = useDynamicContext();

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

  try {
    // Get balance in SUN (smallest unit, 1 TRX = 1,000,000 SUN)
    const balanceInSun = await primaryWallet.getBalance();
    const balanceInTrx = balanceInSun ? Number(balanceInSun) / 1_000_000 : 0;
    console.log('Balance (in TRX):', balanceInTrx);
  } catch (error) {
    console.error('Failed to get balance:', error);
  }
};

Get Token Balance

To get the balance of a TRC20 token, use the getTokenBalance method:
  • React
  • React Native
React
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isTronWallet } from '@dynamic-labs/tron';

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);
    // Balance is returned in the smallest unit (6 decimals for USDT)
    const balanceInTokens = balance / 1_000_000;
    console.log('USDT Balance:', balanceInTokens);
  } catch (error) {
    console.error('Failed to get token balance:', error);
  }
};

Access TronWeb

You can get direct access to the TronWeb instance for advanced operations:
  • React
  • React Native
React
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isTronWallet } from '@dynamic-labs/tron';

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);
};

Get Network Details

To get information about the current network, use the getNetworkDetails method:
  • React
  • React Native
React
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isTronWallet } from '@dynamic-labs/tron';

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);
};

API Reference

Core 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 (in SUN)
  • sendTrx(to: string, amount: number, options?: { from?: string }): Promise<BroadcastReturn> - Send TRX
  • sendTrc20(params): Promise<string | undefined> - Send TRC20 tokens
  • 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

Type Definitions

  • TronWallet - The main wallet class for Tron wallets
  • isTronWallet - Type guard to check if a wallet is a Tron wallet

Resources