> ## 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.

# getTronWeb

# getTronWeb

Retrieves a TronWeb instance from a wallet account, allowing you to interact with the Tron blockchain using the full TronWeb API.

## Usage

```javascript theme={"system"}
import { getTronWeb, isTronWalletAccount } from "@dynamic-labs-sdk/tron";
import { getPrimaryWalletAccount } from "@dynamic-labs-sdk/client";

const walletAccount = getPrimaryWalletAccount();

if (walletAccount && isTronWalletAccount(walletAccount)) {
  const tronWeb = await getTronWeb({ walletAccount });

  // Use TronWeb to interact with the Tron blockchain
  const balance = await tronWeb.trx.getBalance(walletAccount.address);
  console.log("Balance in SUN:", balance);

  // Convert to TRX
  const balanceInTrx = tronWeb.fromSun(balance);
  console.log("Balance in TRX:", balanceInTrx);
}
```

## Parameters

| Parameter       | Type                       | Description                                                             |
| --------------- | -------------------------- | ----------------------------------------------------------------------- |
| `walletAccount` | `TronWalletAccount`        | The wallet account to get the TronWeb instance for                      |
| `client`        | `DynamicClient` (optional) | The Dynamic client instance. Only required when using multiple clients. |

## Returns

`Promise<TronWeb>` - A promise that resolves to a TronWeb instance from the `tronweb` package.

## Errors

| Error                  | Description                                                    |
| ---------------------- | -------------------------------------------------------------- |
| `NotTronProviderError` | Thrown if the wallet account's provider is not a Tron provider |

## React

```tsx theme={"system"}
import { getTronWeb, isTronWalletAccount } from '@dynamic-labs-sdk/tron';
import { useGetWalletAccounts } from '@dynamic-labs-sdk/react-hooks';
import { useEffect, useState } from 'react';

function TronBalance() {
  const { data: walletAccounts = [] } = useGetWalletAccounts();
  const walletAccount = walletAccounts.find(isTronWalletAccount);
  const [balance, setBalance] = useState('');

  useEffect(() => {
    if (!walletAccount) return;
    getTronWeb({ walletAccount }).then(async (tronWeb) => {
      const bal = await tronWeb.trx.getBalance(walletAccount.address);
      setBalance(tronWeb.fromSun(bal));
    });
  }, [walletAccount]);

  return <p>TRX balance: {balance}</p>;
}
```

## Related functions

* [isTronWalletAccount](/javascript/reference/tron/checking-tron-wallet-account-type) - Check if a wallet account is a Tron account
* [sendTransaction](/javascript/reference/tron/send-transaction) - Send a Tron transaction
