@layerzerolabs/tron-utilities 3.0.15 → 3.0.17
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 +18 -0
- package/dist/index.cjs +67 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +259 -0
- package/dist/index.d.ts +259 -0
- package/dist/index.mjs +67 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,90 +1,289 @@
|
|
|
1
1
|
import TronWeb, { TransactionResult, TransactionInfo } from 'tronweb';
|
|
2
2
|
export { BlockTransaction, ChainParameter, ContractExecutionParams, Transaction, default as TronWeb } from 'tronweb';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing the types of transactions that can be performed on the Tron network.
|
|
6
|
+
*/
|
|
4
7
|
declare enum TronTransactionType {
|
|
5
8
|
TRIGGER_SMART_CONTRACT = "TriggerSmartContract"
|
|
6
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Interface representing the overrides for a transaction.
|
|
12
|
+
*/
|
|
7
13
|
interface TransactionOverrides {
|
|
14
|
+
/**
|
|
15
|
+
* The gas limit for the transaction.
|
|
16
|
+
*/
|
|
8
17
|
gasLimit?: number;
|
|
18
|
+
/**
|
|
19
|
+
* The gas price for the transaction.
|
|
20
|
+
*/
|
|
9
21
|
gasPrice?: number;
|
|
22
|
+
/**
|
|
23
|
+
* The energy factor for the transaction.
|
|
24
|
+
*/
|
|
10
25
|
energyFactor?: number;
|
|
26
|
+
/**
|
|
27
|
+
* The value to be sent with the transaction.
|
|
28
|
+
*/
|
|
11
29
|
value?: number;
|
|
12
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Interface representing a partial Tron transaction.
|
|
33
|
+
*/
|
|
13
34
|
interface PartialTronTransaction {
|
|
35
|
+
/**
|
|
36
|
+
* Indicates whether the transaction is visible.
|
|
37
|
+
*/
|
|
14
38
|
visible: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The transaction ID.
|
|
41
|
+
*/
|
|
15
42
|
txID: string;
|
|
43
|
+
/**
|
|
44
|
+
* The raw data in hexadecimal format.
|
|
45
|
+
*/
|
|
16
46
|
raw_data_hex: string;
|
|
47
|
+
/**
|
|
48
|
+
* The raw data of the transaction.
|
|
49
|
+
* @see {@link PartialTronTransactionContract}
|
|
50
|
+
*/
|
|
17
51
|
raw_data: {
|
|
18
52
|
contract: [PartialTronTransactionContract];
|
|
19
53
|
};
|
|
20
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Interface representing a full Tron transaction.
|
|
57
|
+
*/
|
|
21
58
|
interface TronTransaction extends PartialTronTransaction {
|
|
59
|
+
/**
|
|
60
|
+
* The raw data of the transaction.
|
|
61
|
+
*/
|
|
22
62
|
raw_data: {
|
|
63
|
+
/**
|
|
64
|
+
* The contract details of the transaction.
|
|
65
|
+
* @see {@link FullTronTransactionContract}
|
|
66
|
+
*/
|
|
23
67
|
contract: [FullTronTransactionContract];
|
|
68
|
+
/**
|
|
69
|
+
* The reference block bytes.
|
|
70
|
+
*/
|
|
24
71
|
ref_block_bytes: string;
|
|
72
|
+
/**
|
|
73
|
+
* The reference block hash.
|
|
74
|
+
*/
|
|
25
75
|
ref_block_hash: string;
|
|
76
|
+
/**
|
|
77
|
+
* The expiration time of the transaction.
|
|
78
|
+
*/
|
|
26
79
|
expiration: number;
|
|
80
|
+
/**
|
|
81
|
+
* The fee limit for the transaction.
|
|
82
|
+
*/
|
|
27
83
|
fee_limit: number;
|
|
84
|
+
/**
|
|
85
|
+
* The timestamp of the transaction.
|
|
86
|
+
*/
|
|
28
87
|
timestamp: number;
|
|
29
88
|
};
|
|
30
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Interface representing a signed Tron transaction.
|
|
92
|
+
*/
|
|
31
93
|
interface SignedTronTransaction extends TronTransaction {
|
|
94
|
+
/**
|
|
95
|
+
* The signatures of the transaction.
|
|
96
|
+
*/
|
|
32
97
|
signature: string[];
|
|
33
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Interface representing the parameter value of a partial Tron transaction.
|
|
101
|
+
*/
|
|
34
102
|
interface PartialTronTransactionParameterValue {
|
|
103
|
+
/**
|
|
104
|
+
* The data of the transaction.
|
|
105
|
+
*/
|
|
35
106
|
data: string;
|
|
107
|
+
/**
|
|
108
|
+
* The contract address.
|
|
109
|
+
*/
|
|
36
110
|
contract_address: string;
|
|
111
|
+
/**
|
|
112
|
+
* The owner address.
|
|
113
|
+
*/
|
|
37
114
|
owner_address: string;
|
|
38
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Interface representing the parameter value of a full Tron transaction.
|
|
118
|
+
*/
|
|
39
119
|
interface TronTransactionParameterValue extends PartialTronTransactionParameterValue {
|
|
120
|
+
/**
|
|
121
|
+
* The token ID.
|
|
122
|
+
*/
|
|
40
123
|
token_id?: number;
|
|
124
|
+
/**
|
|
125
|
+
* The call token value.
|
|
126
|
+
*/
|
|
41
127
|
call_token_value?: number;
|
|
128
|
+
/**
|
|
129
|
+
* The call value.
|
|
130
|
+
*/
|
|
42
131
|
call_value?: number;
|
|
43
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Interface representing the parameter of a Tron transaction.
|
|
135
|
+
* @template T - The type of the parameter value.
|
|
136
|
+
*/
|
|
44
137
|
interface TronTransactionParameter<T> {
|
|
138
|
+
/**
|
|
139
|
+
* The value of the parameter.
|
|
140
|
+
*/
|
|
45
141
|
value: T;
|
|
142
|
+
/**
|
|
143
|
+
* The type URL of the parameter.
|
|
144
|
+
*/
|
|
46
145
|
type_url: `type.googleapis.com/protocol.${TronTransactionType}`;
|
|
47
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Interface representing a Tron transaction contract.
|
|
149
|
+
* @template T - The type of the parameter value.
|
|
150
|
+
*/
|
|
48
151
|
interface TronTransactionContract<T> {
|
|
152
|
+
/**
|
|
153
|
+
* The parameter of the transaction contract.
|
|
154
|
+
*/
|
|
49
155
|
parameter: TronTransactionParameter<T>;
|
|
156
|
+
/**
|
|
157
|
+
* The type of the transaction contract.
|
|
158
|
+
*/
|
|
50
159
|
type: TronTransactionType;
|
|
160
|
+
/**
|
|
161
|
+
* The permission ID for the transaction contract.
|
|
162
|
+
*/
|
|
51
163
|
Permission_id?: number;
|
|
52
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Type representing a partial Tron transaction contract.
|
|
167
|
+
*/
|
|
53
168
|
type PartialTronTransactionContract = TronTransactionContract<PartialTronTransactionParameterValue>;
|
|
169
|
+
/**
|
|
170
|
+
* Type representing a full Tron transaction contract.
|
|
171
|
+
*/
|
|
54
172
|
type FullTronTransactionContract = TronTransactionContract<TronTransactionParameterValue>;
|
|
173
|
+
/**
|
|
174
|
+
* Interface representing the raw data of a Tron block header.
|
|
175
|
+
*/
|
|
55
176
|
interface TronBlockHeaderRawData {
|
|
177
|
+
/**
|
|
178
|
+
* The block number.
|
|
179
|
+
*/
|
|
56
180
|
number: number;
|
|
181
|
+
/**
|
|
182
|
+
* The transaction trie root.
|
|
183
|
+
*/
|
|
57
184
|
txTrieRoot: string;
|
|
185
|
+
/**
|
|
186
|
+
* The witness address.
|
|
187
|
+
*/
|
|
58
188
|
witness_address: string;
|
|
189
|
+
/**
|
|
190
|
+
* The parent hash.
|
|
191
|
+
*/
|
|
59
192
|
parentHash: string;
|
|
193
|
+
/**
|
|
194
|
+
* The timestamp of the block.
|
|
195
|
+
*/
|
|
60
196
|
timestamp: number;
|
|
61
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Interface representing a Tron block header.
|
|
200
|
+
*/
|
|
62
201
|
interface TronBlockHeader {
|
|
202
|
+
/**
|
|
203
|
+
* The raw data of the block header.
|
|
204
|
+
*/
|
|
63
205
|
raw_data: TronBlockHeaderRawData;
|
|
206
|
+
/**
|
|
207
|
+
* The witness signature.
|
|
208
|
+
*/
|
|
64
209
|
witness_signature: string;
|
|
65
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Interface representing Tron block data.
|
|
213
|
+
*/
|
|
66
214
|
interface TronBlockData {
|
|
215
|
+
/**
|
|
216
|
+
* The block ID.
|
|
217
|
+
*/
|
|
67
218
|
blockID: string;
|
|
219
|
+
/**
|
|
220
|
+
* The block header.
|
|
221
|
+
*/
|
|
68
222
|
block_header: TronBlockHeader;
|
|
69
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Interface representing a TronWeb error response (type 1).
|
|
226
|
+
*/
|
|
70
227
|
interface TronWebError1 {
|
|
228
|
+
/**
|
|
229
|
+
* The error code.
|
|
230
|
+
*/
|
|
71
231
|
code: string;
|
|
232
|
+
/**
|
|
233
|
+
* The error message.
|
|
234
|
+
*/
|
|
72
235
|
message: string;
|
|
236
|
+
/**
|
|
237
|
+
* The transaction ID.
|
|
238
|
+
*/
|
|
73
239
|
txid: string;
|
|
74
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Interface representing a TronWeb error response (type 2).
|
|
243
|
+
*/
|
|
75
244
|
interface TronWebError2 {
|
|
245
|
+
/**
|
|
246
|
+
* The error message.
|
|
247
|
+
*/
|
|
76
248
|
Error: string;
|
|
77
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Type representing a TronWeb error response.
|
|
252
|
+
*/
|
|
78
253
|
type TronWebErrorResponse = TronWebError1 | TronWebError2;
|
|
79
254
|
|
|
255
|
+
/**
|
|
256
|
+
* Type representing provider settings.
|
|
257
|
+
* It can be either a string representing the URL or an object containing the URL and an optional API key.
|
|
258
|
+
*/
|
|
80
259
|
type ProviderSetting = {
|
|
260
|
+
/**
|
|
261
|
+
* The URL of the provider.
|
|
262
|
+
*/
|
|
81
263
|
url: string;
|
|
264
|
+
/**
|
|
265
|
+
* The API key for the provider (optional).
|
|
266
|
+
*/
|
|
82
267
|
apiKey?: string;
|
|
83
268
|
} | string;
|
|
269
|
+
/**
|
|
270
|
+
* Creates a TronWeb instance.
|
|
271
|
+
*
|
|
272
|
+
* @param {{ rpcSetting: ProviderSetting; privateKey: string } | TronWeb} signer - The signer object containing rpcSetting and privateKey, or an existing TronWeb instance.
|
|
273
|
+
* @returns {TronWeb} The created TronWeb instance.
|
|
274
|
+
*/
|
|
84
275
|
declare function createTronWeb(signer: {
|
|
85
276
|
rpcSetting: ProviderSetting;
|
|
86
277
|
privateKey: string;
|
|
87
278
|
} | TronWeb): TronWeb;
|
|
279
|
+
/**
|
|
280
|
+
* Signs and sends a Tron transaction.
|
|
281
|
+
*
|
|
282
|
+
* @param {object} txn - The transaction object containing data, to, and transaction overrides.
|
|
283
|
+
* @param {object} signer - The signer object containing rpcSetting and privateKey, or an existing TronWeb instance.
|
|
284
|
+
* @param {number} [permissionId] - The permission ID for multi-sig.
|
|
285
|
+
* @returns {Promise<object>} A promise that resolves to an object containing txId, result, and wait function.
|
|
286
|
+
*/
|
|
88
287
|
declare function signAndSendTronTransaction(txn: {
|
|
89
288
|
data: string;
|
|
90
289
|
to: string;
|
|
@@ -96,11 +295,28 @@ declare function signAndSendTronTransaction(txn: {
|
|
|
96
295
|
result: TransactionResult;
|
|
97
296
|
wait: () => Promise<TransactionInfo>;
|
|
98
297
|
}>;
|
|
298
|
+
/**
|
|
299
|
+
* Sends a signed Tron transaction.
|
|
300
|
+
*
|
|
301
|
+
* @param {SignedTronTransaction} signedTxn - The signed Tron transaction.
|
|
302
|
+
* @param {TronWeb} client - The TronWeb client.
|
|
303
|
+
* @returns {Promise<object>} A promise that resolves to an object containing txId, result, and wait function.
|
|
304
|
+
* @throws {Error} If the transaction broadcast fails.
|
|
305
|
+
*/
|
|
99
306
|
declare function sendTronTransaction(singedTxn: SignedTronTransaction, client: TronWeb): Promise<{
|
|
100
307
|
txId: string;
|
|
101
308
|
result: TransactionResult;
|
|
102
309
|
wait: () => Promise<TransactionInfo>;
|
|
103
310
|
}>;
|
|
311
|
+
/**
|
|
312
|
+
* Signs a Tron transaction.
|
|
313
|
+
*
|
|
314
|
+
* @param {object} txn - The transaction object containing data, to, and transaction overrides.
|
|
315
|
+
* @param {object} signer - The signer object containing rpcSetting and privateKey, or an existing TronWeb instance.
|
|
316
|
+
* @param {number} [permissionId] - The permission ID for multi-sig.
|
|
317
|
+
* @returns {Promise<SignedTronTransaction>} A promise that resolves to the signed Tron transaction.
|
|
318
|
+
* @throws {Error} If the private key is invalid.
|
|
319
|
+
*/
|
|
104
320
|
declare function signTronTx(txn: {
|
|
105
321
|
data: string;
|
|
106
322
|
to: string;
|
|
@@ -108,15 +324,58 @@ declare function signTronTx(txn: {
|
|
|
108
324
|
rpcSetting: ProviderSetting;
|
|
109
325
|
privateKey: string;
|
|
110
326
|
} | TronWeb, permissionId?: number): Promise<SignedTronTransaction>;
|
|
327
|
+
/**
|
|
328
|
+
* Fills in the missing fields of a Tron transaction.
|
|
329
|
+
*
|
|
330
|
+
* @param {TronWeb} signer - The TronWeb client.
|
|
331
|
+
* @param {PartialTronTransaction} txn - The partial Tron transaction.
|
|
332
|
+
* @param {TransactionOverrides} [overrides={}] - The transaction overrides.
|
|
333
|
+
* @returns {Promise<TronTransaction>} A promise that resolves to the full Tron transaction.
|
|
334
|
+
*/
|
|
111
335
|
declare function fullFillTxn(signer: TronWeb, txn: PartialTronTransaction, overrides?: TransactionOverrides): Promise<TronTransaction>;
|
|
336
|
+
/**
|
|
337
|
+
* Checks the result of a Tron transaction.
|
|
338
|
+
*
|
|
339
|
+
* @param {TronWeb} tronWeb - The TronWeb client.
|
|
340
|
+
* @param {string} txId - The transaction ID.
|
|
341
|
+
* @returns {Promise<TransactionInfo>} A promise that resolves to the transaction info.
|
|
342
|
+
* @throws {Error} If the transaction fails or times out.
|
|
343
|
+
*/
|
|
112
344
|
declare function checkResult(tronWeb: TronWeb, txId: string): Promise<TransactionInfo>;
|
|
113
345
|
|
|
346
|
+
/**
|
|
347
|
+
* Interface representing a provider conversion strategy.
|
|
348
|
+
*/
|
|
114
349
|
interface ProviderConversionStrategy {
|
|
350
|
+
/**
|
|
351
|
+
* Converts a URL to its REST endpoint equivalent.
|
|
352
|
+
*
|
|
353
|
+
* @param {string} url - The URL to convert.
|
|
354
|
+
* @returns {string} The converted REST endpoint URL.
|
|
355
|
+
*/
|
|
115
356
|
asREST(url: string): string;
|
|
357
|
+
/**
|
|
358
|
+
* Converts a URL to its JSON-RPC endpoint equivalent.
|
|
359
|
+
*
|
|
360
|
+
* @param {string} url - The URL to convert.
|
|
361
|
+
* @returns {string} The converted JSON-RPC endpoint URL.
|
|
362
|
+
*/
|
|
116
363
|
asJSONRPC(url: string): string;
|
|
117
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* Class representing a factory for creating provider conversion strategies.
|
|
367
|
+
*/
|
|
118
368
|
declare class StrategyFactory {
|
|
369
|
+
/**
|
|
370
|
+
* A map of URL patterns to provider conversion strategies.
|
|
371
|
+
*/
|
|
119
372
|
static strategies: Map<RegExp, ProviderConversionStrategy>;
|
|
373
|
+
/**
|
|
374
|
+
* Gets the appropriate provider conversion strategy for a given URL.
|
|
375
|
+
*
|
|
376
|
+
* @param {string} url - The URL to get the conversion strategy for.
|
|
377
|
+
* @returns {ProviderConversionStrategy} The provider conversion strategy.
|
|
378
|
+
*/
|
|
120
379
|
static get(url: string): ProviderConversionStrategy;
|
|
121
380
|
}
|
|
122
381
|
|