@dynamic-labs/tron 4.45.1 → 4.45.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,30 @@
1
1
 
2
+ ### [4.45.3](https://github.com/dynamic-labs/dynamic-auth/compare/v4.45.2...v4.45.3) (2025-11-18)
3
+
4
+
5
+ ### Features
6
+
7
+ * add trc20 token transfer to dynamic widget ([#9877](https://github.com/dynamic-labs/dynamic-auth/issues/9877)) ([4365102](https://github.com/dynamic-labs/dynamic-auth/commit/436510253436239d64d4f47b7d0532e65401c19d))
8
+ * add trc20 tokens to sendBalance ([#9873](https://github.com/dynamic-labs/dynamic-auth/issues/9873)) ([fec5e67](https://github.com/dynamic-labs/dynamic-auth/commit/fec5e6715f87fd6a3f7b2ca21c94e4f32ec86031))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * don't allow mobileExperience override to redirect for wallets that don't support it ([#9865](https://github.com/dynamic-labs/dynamic-auth/issues/9865)) ([b34ada5](https://github.com/dynamic-labs/dynamic-auth/commit/b34ada5ac0450667bf33b3cf2ce13e5c16235cfc))
14
+ * **global-wallet:** validate the redirect url ([#9894](https://github.com/dynamic-labs/dynamic-auth/issues/9894)) ([4cf27b5](https://github.com/dynamic-labs/dynamic-auth/commit/4cf27b538da5a9d1da04160faad009880f15f175))
15
+ * temporarily skip Phantom account creation steps due to extension… ([#9893](https://github.com/dynamic-labs/dynamic-auth/issues/9893)) ([87f8a2e](https://github.com/dynamic-labs/dynamic-auth/commit/87f8a2e1185be09c255e7865980f02b13e916db4))
16
+ * wallet book is required console errors ([#9887](https://github.com/dynamic-labs/dynamic-auth/issues/9887)) ([417605d](https://github.com/dynamic-labs/dynamic-auth/commit/417605d605f70ee558dd550b1fb50c996f219b31))
17
+
18
+ ### [4.45.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.45.1...v4.45.2) (2025-11-17)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * assert global wallet url format ([#9876](https://github.com/dynamic-labs/dynamic-auth/issues/9876)) ([6362577](https://github.com/dynamic-labs/dynamic-auth/commit/6362577a37a3e38f94c57e42789798521490cf1a))
24
+ * correct tron testnet chain IDs ([#9872](https://github.com/dynamic-labs/dynamic-auth/issues/9872)) ([98e324f](https://github.com/dynamic-labs/dynamic-auth/commit/98e324f329ba868bd60192edf013ff33dca46d4e))
25
+ * dont send trc20 tokens when calculating gas estimates ([#9880](https://github.com/dynamic-labs/dynamic-auth/issues/9880)) ([ab4edcf](https://github.com/dynamic-labs/dynamic-auth/commit/ab4edcf15567096032fbcd7b1fcb59909adfaecb))
26
+ * **react-native:** register and authenticate with passkey ([#9875](https://github.com/dynamic-labs/dynamic-auth/issues/9875)) ([c6128da](https://github.com/dynamic-labs/dynamic-auth/commit/c6128da4852239bd6ecdc0e8ff97327cc7260a08))
27
+
2
28
  ### [4.45.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.45.0...v4.45.1) (2025-11-14)
3
29
 
4
30
 
package/README.md CHANGED
@@ -320,7 +320,7 @@ This package is written in TypeScript and provides full type definitions. Enable
320
320
 
321
321
  ## License
322
322
 
323
- This package is part of the Dynamic SDK and follows the same licensing terms. See [LICENSE](../../LICENSE) for details.
323
+ This package is part of the Dynamic SDK and follows the same licensing terms. See [LICENSE](../../LICENSE) for details
324
324
 
325
325
  ---
326
326
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.45.1";
6
+ var version = "4.45.3";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.45.1";
2
+ var version = "4.45.3";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/tron",
3
- "version": "4.45.1",
3
+ "version": "4.45.3",
4
4
  "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -18,14 +18,14 @@
18
18
  },
19
19
  "homepage": "https://www.dynamic.xyz/",
20
20
  "dependencies": {
21
- "@dynamic-labs/assert-package-version": "4.45.1",
21
+ "@dynamic-labs/assert-package-version": "4.45.3",
22
22
  "@tronweb3/tronwallet-abstract-adapter": "1.1.9",
23
23
  "@tronweb3/tronwallet-adapters": "1.2.14",
24
24
  "tronweb": "6.0.4",
25
- "@dynamic-labs/types": "4.45.1",
26
- "@dynamic-labs/utils": "4.45.1",
27
- "@dynamic-labs/wallet-book": "4.45.1",
28
- "@dynamic-labs/wallet-connector-core": "4.45.1"
25
+ "@dynamic-labs/types": "4.45.3",
26
+ "@dynamic-labs/utils": "4.45.3",
27
+ "@dynamic-labs/wallet-book": "4.45.3",
28
+ "@dynamic-labs/wallet-connector-core": "4.45.3"
29
29
  },
30
30
  "peerDependencies": {}
31
31
  }
@@ -10,6 +10,7 @@ var utils = require('@dynamic-labs/utils');
10
10
  var TronWallet = require('../../wallet/TronWallet/TronWallet.cjs');
11
11
  var TronUiTransaction = require('../../utils/TronUiTransaction/TronUiTransaction.cjs');
12
12
  var convertChainIdToDecimal = require('../../utils/convertChainIdToDecimal/convertChainIdToDecimal.cjs');
13
+ var getBackwardsCompatibilityTronNetworks = require('../../utils/getBackwardsCompatibilityTronNetworks/getBackwardsCompatibilityTronNetworks.cjs');
13
14
 
14
15
  /**
15
16
  * Registry mapping wallet keys to their adapter classes
@@ -46,7 +47,7 @@ class TronWalletAdapterConnector extends walletConnectorCore.WalletConnectorBase
46
47
  this.adapter = undefined;
47
48
  this.balanceCache = new Map();
48
49
  this.networkCache = null;
49
- this.tronNetworks = opts.tronNetworks;
50
+ this.tronNetworks = getBackwardsCompatibilityTronNetworks.getBackwardsCompatibilityTronNetworks(opts.tronNetworks);
50
51
  this.overrideKey = opts.overrideKey || 'tronwallet';
51
52
  }
52
53
  confirmTransactionStatus() {
@@ -414,8 +415,17 @@ class TronWalletAdapterConnector extends walletConnectorCore.WalletConnectorBase
414
415
  key: 'temp-key',
415
416
  });
416
417
  if (transaction.nonNativeAddress && transaction.nonNativeValue) {
417
- // Handle TRC20 token transfers - not yet implemented
418
- throw new utils.DynamicError('TRC20 token transfers not yet implemented');
418
+ const result = yield wallet.sendTrc20({
419
+ amount: transaction.formatNonNativeToken(transaction.nonNativeValue, transaction.nonNativeDecimal || 18),
420
+ toAddress: transaction.to,
421
+ token: {
422
+ address: transaction.nonNativeAddress,
423
+ },
424
+ });
425
+ if (!result) {
426
+ throw new utils.DynamicError('Failed to send TRC20 token');
427
+ }
428
+ return result;
419
429
  }
420
430
  else if (transaction.value) {
421
431
  // Handle native TRX transfers
@@ -6,6 +6,7 @@ import { DynamicError } from '@dynamic-labs/utils';
6
6
  import { TronWallet } from '../../wallet/TronWallet/TronWallet.js';
7
7
  import { TronUiTransaction } from '../../utils/TronUiTransaction/TronUiTransaction.js';
8
8
  import { convertChainIdToDecimal } from '../../utils/convertChainIdToDecimal/convertChainIdToDecimal.js';
9
+ import { getBackwardsCompatibilityTronNetworks } from '../../utils/getBackwardsCompatibilityTronNetworks/getBackwardsCompatibilityTronNetworks.js';
9
10
 
10
11
  /**
11
12
  * Registry mapping wallet keys to their adapter classes
@@ -42,7 +43,7 @@ class TronWalletAdapterConnector extends WalletConnectorBase {
42
43
  this.adapter = undefined;
43
44
  this.balanceCache = new Map();
44
45
  this.networkCache = null;
45
- this.tronNetworks = opts.tronNetworks;
46
+ this.tronNetworks = getBackwardsCompatibilityTronNetworks(opts.tronNetworks);
46
47
  this.overrideKey = opts.overrideKey || 'tronwallet';
47
48
  }
48
49
  confirmTransactionStatus() {
@@ -410,8 +411,17 @@ class TronWalletAdapterConnector extends WalletConnectorBase {
410
411
  key: 'temp-key',
411
412
  });
412
413
  if (transaction.nonNativeAddress && transaction.nonNativeValue) {
413
- // Handle TRC20 token transfers - not yet implemented
414
- throw new DynamicError('TRC20 token transfers not yet implemented');
414
+ const result = yield wallet.sendTrc20({
415
+ amount: transaction.formatNonNativeToken(transaction.nonNativeValue, transaction.nonNativeDecimal || 18),
416
+ toAddress: transaction.to,
417
+ token: {
418
+ address: transaction.nonNativeAddress,
419
+ },
420
+ });
421
+ if (!result) {
422
+ throw new DynamicError('Failed to send TRC20 token');
423
+ }
424
+ return result;
415
425
  }
416
426
  else if (transaction.value) {
417
427
  // Handle native TRX transfers
@@ -0,0 +1,19 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const getBackwardsCompatibilityTronNetworks = (networks) => networks.reduce((acc, network) => {
7
+ if (network.chainId === '728126429') {
8
+ acc.push(Object.assign(Object.assign({}, network), { chainId: '2494104990', networkId: '2494104990' }));
9
+ }
10
+ else if (network.chainId === '728126430') {
11
+ acc.push(Object.assign(Object.assign({}, network), { chainId: '3448148188', networkId: '3448148188' }));
12
+ }
13
+ else {
14
+ acc.push(network);
15
+ }
16
+ return acc;
17
+ }, []);
18
+
19
+ exports.getBackwardsCompatibilityTronNetworks = getBackwardsCompatibilityTronNetworks;
@@ -0,0 +1,2 @@
1
+ import { GenericNetwork } from '@dynamic-labs/types';
2
+ export declare const getBackwardsCompatibilityTronNetworks: (networks: GenericNetwork[]) => GenericNetwork[];
@@ -0,0 +1,15 @@
1
+ 'use client'
2
+ const getBackwardsCompatibilityTronNetworks = (networks) => networks.reduce((acc, network) => {
3
+ if (network.chainId === '728126429') {
4
+ acc.push(Object.assign(Object.assign({}, network), { chainId: '2494104990', networkId: '2494104990' }));
5
+ }
6
+ else if (network.chainId === '728126430') {
7
+ acc.push(Object.assign(Object.assign({}, network), { chainId: '3448148188', networkId: '3448148188' }));
8
+ }
9
+ else {
10
+ acc.push(network);
11
+ }
12
+ return acc;
13
+ }, []);
14
+
15
+ export { getBackwardsCompatibilityTronNetworks };
@@ -0,0 +1 @@
1
+ export { getBackwardsCompatibilityTronNetworks } from './getBackwardsCompatibilityTronNetworks';
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../../../_virtual/_tslib.cjs');
7
7
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
8
+ var TronUiTransaction = require('../TronUiTransaction/TronUiTransaction.cjs');
8
9
 
9
10
  /**
10
11
  * Extract fee from transaction data
@@ -40,6 +41,45 @@ const hasAvailableBandwidth = (from, tronWeb) => _tslib.__awaiter(void 0, void 0
40
41
  const freeNetUsed = (accountResources === null || accountResources === void 0 ? void 0 : accountResources.freeNetUsed) || 0;
41
42
  return freeNetUsed < freeNetLimit;
42
43
  });
44
+ /**
45
+ * Get energy price from chain (in SUN per energy unit)
46
+ * Defaults to 420 SUN per energy if not available
47
+ */
48
+ const getEnergyPrice = (tronWeb) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
49
+ var _a;
50
+ try {
51
+ const chainParameters = yield tronWeb.trx.getChainParameters();
52
+ const energyPrice = (_a = chainParameters === null || chainParameters === void 0 ? void 0 : chainParameters.find((param) => param.key === 'getEnergyFee')) === null || _a === void 0 ? void 0 : _a.value;
53
+ return energyPrice || 420; // Default to 420 SUN per energy
54
+ }
55
+ catch (error) {
56
+ walletConnectorCore.logger.debug('Failed to get energy price, using default:', error);
57
+ return 420; // Default to 420 SUN per energy
58
+ }
59
+ });
60
+ const getTrc20EnergyEstimationUsingTronWebApi = (from, to, nonNativeAddress, nonNativeValue, tronWeb) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
61
+ const functionSelector = 'transfer(address,uint256)';
62
+ const parameter = [
63
+ { type: 'address', value: to },
64
+ { type: 'uint256', value: nonNativeValue.toString() },
65
+ ];
66
+ try {
67
+ const est = yield tronWeb.transactionBuilder.estimateEnergy(nonNativeAddress, functionSelector, {}, // options for call value, etc.
68
+ parameter, from);
69
+ const energyRequired = est.energy_required;
70
+ const energyPrice = yield getEnergyPrice(tronWeb);
71
+ const feeInSun = energyRequired * energyPrice;
72
+ const feeInTrx = feeInSun / TronUiTransaction.SUN_PER_TRX;
73
+ return {
74
+ energy: energyRequired,
75
+ feeInTrx,
76
+ };
77
+ }
78
+ catch (error) {
79
+ walletConnectorCore.logger.debug('TRC20 energy estimation failed, using conservative estimate:', error);
80
+ return;
81
+ }
82
+ });
43
83
  /**
44
84
  * Estimate TRC20 token transfer fees
45
85
  * @param from - The sender's address
@@ -55,17 +95,14 @@ const estimateTRC20Fees = (from, to, nonNativeAddress, nonNativeValue, tronWeb)
55
95
  if (yield hasAvailableEnergy(from, tronWeb)) {
56
96
  return BigInt(0);
57
97
  }
58
- // Try to get actual fee from contract
98
+ // Calculate TRC20 energy estimate for transfer and return fee in TRX
59
99
  try {
60
- const contract = yield tronWeb.contract().at(nonNativeAddress);
61
- const transaction = yield contract
62
- .transfer(to, nonNativeValue.toString())
63
- .send({
64
- feeLimit: 100000000, // 100 TRX max fee limit
65
- from,
66
- });
67
- const fee = extractFeeFromTransaction(transaction);
68
- return BigInt(fee);
100
+ const energyEstimate = yield getTrc20EnergyEstimationUsingTronWebApi(from, to, nonNativeAddress, nonNativeValue, tronWeb);
101
+ if (energyEstimate) {
102
+ // Convert TRX to SUN for return value (maintaining API compatibility)
103
+ return BigInt(Math.ceil(energyEstimate.feeInTrx * TronUiTransaction.SUN_PER_TRX));
104
+ }
105
+ return BigInt(1000000); // ~1 TRX max (in SUN)
69
106
  }
70
107
  catch (contractError) {
71
108
  walletConnectorCore.logger.debug('TRC20 contract estimation failed, using conservative estimate:', contractError);
@@ -1,6 +1,7 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../_virtual/_tslib.js';
3
3
  import { logger } from '@dynamic-labs/wallet-connector-core';
4
+ import { SUN_PER_TRX } from '../TronUiTransaction/TronUiTransaction.js';
4
5
 
5
6
  /**
6
7
  * Extract fee from transaction data
@@ -36,6 +37,45 @@ const hasAvailableBandwidth = (from, tronWeb) => __awaiter(void 0, void 0, void
36
37
  const freeNetUsed = (accountResources === null || accountResources === void 0 ? void 0 : accountResources.freeNetUsed) || 0;
37
38
  return freeNetUsed < freeNetLimit;
38
39
  });
40
+ /**
41
+ * Get energy price from chain (in SUN per energy unit)
42
+ * Defaults to 420 SUN per energy if not available
43
+ */
44
+ const getEnergyPrice = (tronWeb) => __awaiter(void 0, void 0, void 0, function* () {
45
+ var _a;
46
+ try {
47
+ const chainParameters = yield tronWeb.trx.getChainParameters();
48
+ const energyPrice = (_a = chainParameters === null || chainParameters === void 0 ? void 0 : chainParameters.find((param) => param.key === 'getEnergyFee')) === null || _a === void 0 ? void 0 : _a.value;
49
+ return energyPrice || 420; // Default to 420 SUN per energy
50
+ }
51
+ catch (error) {
52
+ logger.debug('Failed to get energy price, using default:', error);
53
+ return 420; // Default to 420 SUN per energy
54
+ }
55
+ });
56
+ const getTrc20EnergyEstimationUsingTronWebApi = (from, to, nonNativeAddress, nonNativeValue, tronWeb) => __awaiter(void 0, void 0, void 0, function* () {
57
+ const functionSelector = 'transfer(address,uint256)';
58
+ const parameter = [
59
+ { type: 'address', value: to },
60
+ { type: 'uint256', value: nonNativeValue.toString() },
61
+ ];
62
+ try {
63
+ const est = yield tronWeb.transactionBuilder.estimateEnergy(nonNativeAddress, functionSelector, {}, // options for call value, etc.
64
+ parameter, from);
65
+ const energyRequired = est.energy_required;
66
+ const energyPrice = yield getEnergyPrice(tronWeb);
67
+ const feeInSun = energyRequired * energyPrice;
68
+ const feeInTrx = feeInSun / SUN_PER_TRX;
69
+ return {
70
+ energy: energyRequired,
71
+ feeInTrx,
72
+ };
73
+ }
74
+ catch (error) {
75
+ logger.debug('TRC20 energy estimation failed, using conservative estimate:', error);
76
+ return;
77
+ }
78
+ });
39
79
  /**
40
80
  * Estimate TRC20 token transfer fees
41
81
  * @param from - The sender's address
@@ -51,17 +91,14 @@ const estimateTRC20Fees = (from, to, nonNativeAddress, nonNativeValue, tronWeb)
51
91
  if (yield hasAvailableEnergy(from, tronWeb)) {
52
92
  return BigInt(0);
53
93
  }
54
- // Try to get actual fee from contract
94
+ // Calculate TRC20 energy estimate for transfer and return fee in TRX
55
95
  try {
56
- const contract = yield tronWeb.contract().at(nonNativeAddress);
57
- const transaction = yield contract
58
- .transfer(to, nonNativeValue.toString())
59
- .send({
60
- feeLimit: 100000000, // 100 TRX max fee limit
61
- from,
62
- });
63
- const fee = extractFeeFromTransaction(transaction);
64
- return BigInt(fee);
96
+ const energyEstimate = yield getTrc20EnergyEstimationUsingTronWebApi(from, to, nonNativeAddress, nonNativeValue, tronWeb);
97
+ if (energyEstimate) {
98
+ // Convert TRX to SUN for return value (maintaining API compatibility)
99
+ return BigInt(Math.ceil(energyEstimate.feeInTrx * SUN_PER_TRX));
100
+ }
101
+ return BigInt(1000000); // ~1 TRX max (in SUN)
65
102
  }
66
103
  catch (contractError) {
67
104
  logger.debug('TRC20 contract estimation failed, using conservative estimate:', contractError);
@@ -0,0 +1 @@
1
+ export { isNonNativeTronTransactionType } from './nonNativeTronTransactionType';
@@ -0,0 +1,16 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const isNonNativeTronTransactionType = (contractAddress) => {
7
+ if (!isNaN(Number(contractAddress))) {
8
+ return 'trc10';
9
+ }
10
+ if (contractAddress.startsWith('T')) {
11
+ return 'trc20';
12
+ }
13
+ return undefined;
14
+ };
15
+
16
+ exports.isNonNativeTronTransactionType = isNonNativeTronTransactionType;
@@ -0,0 +1 @@
1
+ export declare const isNonNativeTronTransactionType: (contractAddress: string) => 'trc20' | 'trc10' | undefined;
@@ -0,0 +1,12 @@
1
+ 'use client'
2
+ const isNonNativeTronTransactionType = (contractAddress) => {
3
+ if (!isNaN(Number(contractAddress))) {
4
+ return 'trc10';
5
+ }
6
+ if (contractAddress.startsWith('T')) {
7
+ return 'trc20';
8
+ }
9
+ return undefined;
10
+ };
11
+
12
+ export { isNonNativeTronTransactionType };
@@ -6,6 +6,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
6
6
  var _tslib = require('../../../_virtual/_tslib.cjs');
7
7
  var utils = require('@dynamic-labs/utils');
8
8
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
9
+ var nonNativeTronTransactionType = require('../../utils/nonNativeTronTransactionType/nonNativeTronTransactionType.cjs');
10
+ var getTronGasEstimation = require('../../utils/getTronGasEstimation/getTronGasEstimation.cjs');
9
11
 
10
12
  class TronWallet extends walletConnectorCore.Wallet {
11
13
  constructor(props) {
@@ -48,11 +50,74 @@ class TronWallet extends walletConnectorCore.Wallet {
48
50
  * Send balance (sends TRX)
49
51
  */
50
52
  sendBalance(_a) {
51
- return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
53
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, }) {
54
+ if (token && token.address) {
55
+ const transactionType = nonNativeTronTransactionType.isNonNativeTronTransactionType(token.address);
56
+ if (transactionType === 'trc20') {
57
+ const result = yield this.sendTrc20({
58
+ amount,
59
+ toAddress,
60
+ token,
61
+ });
62
+ return result;
63
+ }
64
+ throw new utils.DynamicError(`Unsupported transaction type: ${transactionType}`);
65
+ }
52
66
  const result = yield this.sendTrx(toAddress, Number(amount));
53
67
  return result.txid;
54
68
  });
55
69
  }
70
+ /**
71
+ * Send TRC20 token to an address
72
+ *
73
+ * @param amount - Amount as a string (in token units, e.g., "1.5" for 1.5 tokens)
74
+ * @param toAddress - Recipient address
75
+ * @param token - Token contract address and decimals
76
+ * @param options - Optional parameters including from address and fee limit
77
+ * @returns Transaction result with txid
78
+ */
79
+ sendTrc20(_a) {
80
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, options, }) {
81
+ var _b;
82
+ const tronWeb = this.getTronWeb();
83
+ if (!(tronWeb === null || tronWeb === void 0 ? void 0 : tronWeb.contract)) {
84
+ throw new utils.DynamicError('TRC20 token operations not supported by this wallet');
85
+ }
86
+ const contract = yield tronWeb.contract().at(token.address);
87
+ const fromAddress = (options === null || options === void 0 ? void 0 : options.from) || this.address;
88
+ //
89
+ const decimals = token.decimals || Number((_b = (yield contract.decimals().call())) === null || _b === void 0 ? void 0 : _b.toString());
90
+ // Convert amount to smallest unit (considering decimals)
91
+ // e.g., if amount is "1.5" and decimals is 18, result should be "1500000000000000000"
92
+ const amountNumber = parseFloat(amount);
93
+ if (isNaN(amountNumber) || amountNumber < 0) {
94
+ throw new utils.DynamicError('Invalid token amount');
95
+ }
96
+ const amountInSmallestUnit = BigInt(Math.floor(amountNumber * Math.pow(10, decimals)));
97
+ // Default 5 TRX max fee limit until we implement the gas estimation
98
+ const feeLimit = (options === null || options === void 0 ? void 0 : options.feeLimit) ||
99
+ (yield getTronGasEstimation.getTronGasEstimation({
100
+ from: fromAddress,
101
+ nonNativeAddress: token.address,
102
+ nonNativeValue: amountInSmallestUnit,
103
+ to: toAddress,
104
+ tronWeb,
105
+ })) ||
106
+ 5000000;
107
+ try {
108
+ const result = yield contract
109
+ .transfer(toAddress, amountInSmallestUnit.toString())
110
+ .send({
111
+ feeLimit: feeLimit || 5000000, // Default 5 TRX max fee limit
112
+ from: fromAddress,
113
+ });
114
+ return result;
115
+ }
116
+ catch (error) {
117
+ throw new utils.DynamicError(`Failed to send TRC20 token: ${error instanceof Error ? error.message : String(error)}`);
118
+ }
119
+ });
120
+ }
56
121
  /**
57
122
  * Send TRX to an address
58
123
  *
@@ -18,9 +18,34 @@ export declare class TronWallet extends Wallet<TronWalletAdapterConnector> {
18
18
  /**
19
19
  * Send balance (sends TRX)
20
20
  */
21
- sendBalance({ amount, toAddress, }: {
21
+ sendBalance({ amount, toAddress, token, }: {
22
22
  amount: string;
23
23
  toAddress: string;
24
+ token?: {
25
+ address: string;
26
+ decimals?: number;
27
+ };
28
+ }): Promise<string | undefined>;
29
+ /**
30
+ * Send TRC20 token to an address
31
+ *
32
+ * @param amount - Amount as a string (in token units, e.g., "1.5" for 1.5 tokens)
33
+ * @param toAddress - Recipient address
34
+ * @param token - Token contract address and decimals
35
+ * @param options - Optional parameters including from address and fee limit
36
+ * @returns Transaction result with txid
37
+ */
38
+ sendTrc20({ amount, toAddress, token, options, }: {
39
+ amount: string;
40
+ toAddress: string;
41
+ token: {
42
+ address: string;
43
+ decimals?: number;
44
+ };
45
+ options?: {
46
+ from?: string;
47
+ feeLimit?: number;
48
+ };
24
49
  }): Promise<string | undefined>;
25
50
  /**
26
51
  * Send TRX to an address
@@ -2,6 +2,8 @@
2
2
  import { __awaiter } from '../../../_virtual/_tslib.js';
3
3
  import { DynamicError } from '@dynamic-labs/utils';
4
4
  import { Wallet } from '@dynamic-labs/wallet-connector-core';
5
+ import { isNonNativeTronTransactionType } from '../../utils/nonNativeTronTransactionType/nonNativeTronTransactionType.js';
6
+ import { getTronGasEstimation } from '../../utils/getTronGasEstimation/getTronGasEstimation.js';
5
7
 
6
8
  class TronWallet extends Wallet {
7
9
  constructor(props) {
@@ -44,11 +46,74 @@ class TronWallet extends Wallet {
44
46
  * Send balance (sends TRX)
45
47
  */
46
48
  sendBalance(_a) {
47
- return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
49
+ return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, }) {
50
+ if (token && token.address) {
51
+ const transactionType = isNonNativeTronTransactionType(token.address);
52
+ if (transactionType === 'trc20') {
53
+ const result = yield this.sendTrc20({
54
+ amount,
55
+ toAddress,
56
+ token,
57
+ });
58
+ return result;
59
+ }
60
+ throw new DynamicError(`Unsupported transaction type: ${transactionType}`);
61
+ }
48
62
  const result = yield this.sendTrx(toAddress, Number(amount));
49
63
  return result.txid;
50
64
  });
51
65
  }
66
+ /**
67
+ * Send TRC20 token to an address
68
+ *
69
+ * @param amount - Amount as a string (in token units, e.g., "1.5" for 1.5 tokens)
70
+ * @param toAddress - Recipient address
71
+ * @param token - Token contract address and decimals
72
+ * @param options - Optional parameters including from address and fee limit
73
+ * @returns Transaction result with txid
74
+ */
75
+ sendTrc20(_a) {
76
+ return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, options, }) {
77
+ var _b;
78
+ const tronWeb = this.getTronWeb();
79
+ if (!(tronWeb === null || tronWeb === void 0 ? void 0 : tronWeb.contract)) {
80
+ throw new DynamicError('TRC20 token operations not supported by this wallet');
81
+ }
82
+ const contract = yield tronWeb.contract().at(token.address);
83
+ const fromAddress = (options === null || options === void 0 ? void 0 : options.from) || this.address;
84
+ //
85
+ const decimals = token.decimals || Number((_b = (yield contract.decimals().call())) === null || _b === void 0 ? void 0 : _b.toString());
86
+ // Convert amount to smallest unit (considering decimals)
87
+ // e.g., if amount is "1.5" and decimals is 18, result should be "1500000000000000000"
88
+ const amountNumber = parseFloat(amount);
89
+ if (isNaN(amountNumber) || amountNumber < 0) {
90
+ throw new DynamicError('Invalid token amount');
91
+ }
92
+ const amountInSmallestUnit = BigInt(Math.floor(amountNumber * Math.pow(10, decimals)));
93
+ // Default 5 TRX max fee limit until we implement the gas estimation
94
+ const feeLimit = (options === null || options === void 0 ? void 0 : options.feeLimit) ||
95
+ (yield getTronGasEstimation({
96
+ from: fromAddress,
97
+ nonNativeAddress: token.address,
98
+ nonNativeValue: amountInSmallestUnit,
99
+ to: toAddress,
100
+ tronWeb,
101
+ })) ||
102
+ 5000000;
103
+ try {
104
+ const result = yield contract
105
+ .transfer(toAddress, amountInSmallestUnit.toString())
106
+ .send({
107
+ feeLimit: feeLimit || 5000000, // Default 5 TRX max fee limit
108
+ from: fromAddress,
109
+ });
110
+ return result;
111
+ }
112
+ catch (error) {
113
+ throw new DynamicError(`Failed to send TRC20 token: ${error instanceof Error ? error.message : String(error)}`);
114
+ }
115
+ });
116
+ }
52
117
  /**
53
118
  * Send TRX to an address
54
119
  *