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

Usage

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

ParameterTypeDescription
walletAccountTronWalletAccountThe wallet account to get the TronWeb instance for
clientDynamicClient (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

ErrorDescription
NotTronProviderErrorThrown if the wallet account’s provider is not a Tron provider