> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Tron Wallets

<Card title="Recommended: JavaScript SDK with React Hooks" icon="react" color="#4779FE">
  For new React apps, we recommend the JavaScript SDK with React Hooks (`@dynamic-labs-sdk/react-hooks`) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the [React quickstart (JavaScript SDK)](/javascript/reference/react-quickstart) to get started.
</Card>

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](https://walletadapter.org). This provides access to 9+ Tron wallets through a single, unified interface.

## Installation

First, install the Tron wallet connector package:

```bash theme={"system"}
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           |

## Supported Networks

| Network            | Chain ID  | Description        | Block Explorer                                  |
| ------------------ | --------- | ------------------ | ----------------------------------------------- |
| **Tron Mainnet**   | 728126428 | Production network | [Tronscan](https://tronscan.org/)               |
| **Shasta Testnet** | 728126429 | Test network       | [Shasta Tronscan](https://shasta.tronscan.org/) |
| **Nile Testnet**   | 728126430 | Test network       | [Nile Tronscan](https://nile.tronscan.org/)     |

## Basic Integration

To use Tron wallets in your app, add the Tron wallet connectors to your Dynamic configuration:

```tsx React theme={"system"}
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.

```tsx React theme={"system"}
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:

```tsx React theme={"system"}
const { primaryWallet } = useDynamicContext();

const tronAddress = primaryWallet.address;
```

## Send TRX

To send TRX (the native Tron currency) to another address, use the `sendTrx` method:

```tsx React theme={"system"}
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:

```tsx React theme={"system"}
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`:

```tsx React theme={"system"}
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:

```tsx React theme={"system"}
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:

```tsx React theme={"system"}
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:

```tsx React theme={"system"}
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:

```tsx React theme={"system"}
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

* **TronWallet Adapter Docs**: [https://walletadapter.org/docs/](https://walletadapter.org/docs/)
* **TronWeb Docs**: [https://developers.tron.network/docs](https://developers.tron.network/docs)
* **Tron Network**: [https://tron.network](https://tron.network)
