@dynamic-labs/tron 4.45.2 → 4.46.0

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,28 @@
1
1
 
2
+ ## [4.46.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.45.3...v4.46.0) (2025-11-19)
3
+
4
+
5
+ ### Features
6
+
7
+ * **react-native:** add client.solana.simulateTransaction method ([#9910](https://github.com/dynamic-labs/dynamic-auth/issues/9910)) ([61bbe45](https://github.com/dynamic-labs/dynamic-auth/commit/61bbe453eeb2790dffc533aa57f6bc050c3c0461))
8
+ * **react-native:** add simulateEVMTransactionAA and simulateEVMTransaction methods ([#9907](https://github.com/dynamic-labs/dynamic-auth/issues/9907)) ([e54d63e](https://github.com/dynamic-labs/dynamic-auth/commit/e54d63eaa80c2bc865ef6199405b0ed7943d4b83))
9
+
10
+ ### [4.45.3](https://github.com/dynamic-labs/dynamic-auth/compare/v4.45.2...v4.45.3) (2025-11-18)
11
+
12
+
13
+ ### Features
14
+
15
+ * 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))
16
+ * 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))
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * 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))
22
+ * **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))
23
+ * 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))
24
+ * 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))
25
+
2
26
  ### [4.45.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.45.1...v4.45.2) (2025-11-17)
3
27
 
4
28
 
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.2";
6
+ var version = "4.46.0";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.45.2";
2
+ var version = "4.46.0";
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.2",
3
+ "version": "4.46.0",
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.2",
21
+ "@dynamic-labs/assert-package-version": "4.46.0",
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.2",
26
- "@dynamic-labs/utils": "4.45.2",
27
- "@dynamic-labs/wallet-book": "4.45.2",
28
- "@dynamic-labs/wallet-connector-core": "4.45.2"
25
+ "@dynamic-labs/types": "4.46.0",
26
+ "@dynamic-labs/utils": "4.46.0",
27
+ "@dynamic-labs/wallet-book": "4.46.0",
28
+ "@dynamic-labs/wallet-connector-core": "4.46.0"
29
29
  },
30
30
  "peerDependencies": {}
31
31
  }
@@ -415,8 +415,17 @@ class TronWalletAdapterConnector extends walletConnectorCore.WalletConnectorBase
415
415
  key: 'temp-key',
416
416
  });
417
417
  if (transaction.nonNativeAddress && transaction.nonNativeValue) {
418
- // Handle TRC20 token transfers - not yet implemented
419
- 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;
420
429
  }
421
430
  else if (transaction.value) {
422
431
  // Handle native TRX transfers
@@ -411,8 +411,17 @@ class TronWalletAdapterConnector extends WalletConnectorBase {
411
411
  key: 'temp-key',
412
412
  });
413
413
  if (transaction.nonNativeAddress && transaction.nonNativeValue) {
414
- // Handle TRC20 token transfers - not yet implemented
415
- 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;
416
425
  }
417
426
  else if (transaction.value) {
418
427
  // Handle native TRX transfers
@@ -102,16 +102,16 @@ const estimateTRC20Fees = (from, to, nonNativeAddress, nonNativeValue, tronWeb)
102
102
  // Convert TRX to SUN for return value (maintaining API compatibility)
103
103
  return BigInt(Math.ceil(energyEstimate.feeInTrx * TronUiTransaction.SUN_PER_TRX));
104
104
  }
105
- return BigInt(1000000); // ~1 TRX max (in SUN)
105
+ return BigInt(18000000); // ~18 TRX max (in SUN)
106
106
  }
107
107
  catch (contractError) {
108
108
  walletConnectorCore.logger.debug('TRC20 contract estimation failed, using conservative estimate:', contractError);
109
- return BigInt(1000000); // ~1 TRX max
109
+ return BigInt(18000000); // ~18 TRX max
110
110
  }
111
111
  }
112
112
  catch (error) {
113
113
  walletConnectorCore.logger.debug('TRC20 estimation failed, defaulting to conservative estimate:', error);
114
- return BigInt(1000000); // ~1 TRX max
114
+ return BigInt(18000000); // ~18 TRX max
115
115
  }
116
116
  });
117
117
  /**
@@ -138,12 +138,12 @@ const estimateTRXFees = (from, to, value, tronWeb) => _tslib.__awaiter(void 0, v
138
138
  }
139
139
  catch (txError) {
140
140
  walletConnectorCore.logger.debug('TRX transaction estimation failed, using conservative estimate:', txError);
141
- return BigInt(100000); // ~0.1 TRX max
141
+ return BigInt(18000000); // ~18 TRX max
142
142
  }
143
143
  }
144
144
  catch (error) {
145
145
  walletConnectorCore.logger.debug('TRX estimation failed, defaulting to conservative estimate:', error);
146
- return BigInt(100000); // ~0.1 TRX max
146
+ return BigInt(18000000); // ~18 TRX max
147
147
  }
148
148
  });
149
149
  /**
@@ -98,16 +98,16 @@ const estimateTRC20Fees = (from, to, nonNativeAddress, nonNativeValue, tronWeb)
98
98
  // Convert TRX to SUN for return value (maintaining API compatibility)
99
99
  return BigInt(Math.ceil(energyEstimate.feeInTrx * SUN_PER_TRX));
100
100
  }
101
- return BigInt(1000000); // ~1 TRX max (in SUN)
101
+ return BigInt(18000000); // ~18 TRX max (in SUN)
102
102
  }
103
103
  catch (contractError) {
104
104
  logger.debug('TRC20 contract estimation failed, using conservative estimate:', contractError);
105
- return BigInt(1000000); // ~1 TRX max
105
+ return BigInt(18000000); // ~18 TRX max
106
106
  }
107
107
  }
108
108
  catch (error) {
109
109
  logger.debug('TRC20 estimation failed, defaulting to conservative estimate:', error);
110
- return BigInt(1000000); // ~1 TRX max
110
+ return BigInt(18000000); // ~18 TRX max
111
111
  }
112
112
  });
113
113
  /**
@@ -134,12 +134,12 @@ const estimateTRXFees = (from, to, value, tronWeb) => __awaiter(void 0, void 0,
134
134
  }
135
135
  catch (txError) {
136
136
  logger.debug('TRX transaction estimation failed, using conservative estimate:', txError);
137
- return BigInt(100000); // ~0.1 TRX max
137
+ return BigInt(18000000); // ~18 TRX max
138
138
  }
139
139
  }
140
140
  catch (error) {
141
141
  logger.debug('TRX estimation failed, defaulting to conservative estimate:', error);
142
- return BigInt(100000); // ~0.1 TRX max
142
+ return BigInt(18000000); // ~18 TRX max
143
143
  }
144
144
  });
145
145
  /**
@@ -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
  *