@xchainjs/xchain-tron 2.0.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/LICENSE +21 -0
- package/README.md +35 -0
- package/lib/client.d.ts +153 -0
- package/lib/clientKeystore.d.ts +22 -0
- package/lib/const.d.ts +22 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.esm.js +1024 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.js +1045 -0
- package/lib/index.js.map +1 -0
- package/lib/types.d.ts +38 -0
- package/lib/utils/index.d.ts +3 -0
- package/lib/utils/trongrid/index.d.ts +2 -0
- package/lib/utils/trongrid/trongrid.d.ts +57 -0
- package/lib/utils/trongrid/types.d.ts +137 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 THORChain
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# `@xchainjs/xchain-tron`
|
|
2
|
+
|
|
3
|
+
## Modules
|
|
4
|
+
|
|
5
|
+
- `client` - Custom client for Tron
|
|
6
|
+
- `clientKeystore` - Keystore client for Tron
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
yarn add @xchainjs/xchain-tron
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Following peer dependencies have to be installed into your project. These are not included in `@xchainjs/xchain-tron`.
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
yarn add @xchainjs/xchain-client @xchainjs/xchain-crypto @xchainjs/xchain-util
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Basic Transfer
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { ClientKeystore as Client, AssetTRX } from '@xchainjs/xchain-tron'
|
|
26
|
+
import { assetToBase, assetAmount } from '@xchainjs/xchain-util'
|
|
27
|
+
|
|
28
|
+
const client = new Client({ phrase: 'your mnemonic phrase' })
|
|
29
|
+
|
|
30
|
+
// Simple transfer
|
|
31
|
+
const txHash = await client.transfer({
|
|
32
|
+
asset: AssetTRX,
|
|
33
|
+
amount: assetToBase(assetAmount('1', 6)), // 1 TRX
|
|
34
|
+
})
|
|
35
|
+
```
|
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { AssetInfo, Fees, Balance, TxHash, BaseXChainClient, ExplorerProviders, TxParams, PreparedTx, TxsPage, TxHistoryParams, Tx, FeesWithRates, FeeRate } from '@xchainjs/xchain-client';
|
|
2
|
+
import { Address } from '@xchainjs/xchain-util';
|
|
3
|
+
import { TronWeb } from 'tronweb';
|
|
4
|
+
import { TRONClientParams, TronTransaction, TronSignedTransaction, ApproveParams, IsApprovedParams, TronGetApprovedParams } from './types';
|
|
5
|
+
import { TronGrid } from './utils/trongrid';
|
|
6
|
+
export declare const defaultTRONParams: TRONClientParams;
|
|
7
|
+
export declare abstract class Client extends BaseXChainClient {
|
|
8
|
+
protected explorerProviders: ExplorerProviders;
|
|
9
|
+
protected tronWeb: TronWeb;
|
|
10
|
+
protected tronGrid: TronGrid;
|
|
11
|
+
constructor(params?: TRONClientParams);
|
|
12
|
+
/**
|
|
13
|
+
* Get TRX asset info.
|
|
14
|
+
* @returns {AssetInfo} TRX asset information.
|
|
15
|
+
*/
|
|
16
|
+
getAssetInfo(): AssetInfo;
|
|
17
|
+
/**
|
|
18
|
+
* Get the explorer URL.
|
|
19
|
+
*
|
|
20
|
+
* @returns {string} The explorer URL.
|
|
21
|
+
*/
|
|
22
|
+
getExplorerUrl(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Get the explorer url for the given address.
|
|
25
|
+
*
|
|
26
|
+
* @param {Address} address
|
|
27
|
+
* @returns {string} The explorer url for the given address.
|
|
28
|
+
*/
|
|
29
|
+
getExplorerAddressUrl(address: Address): string;
|
|
30
|
+
/**
|
|
31
|
+
* Get the explorer url for the given transaction id.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} txID
|
|
34
|
+
* @returns {string} The explorer url for the given transaction id.
|
|
35
|
+
*/
|
|
36
|
+
getExplorerTxUrl(txID: TxHash): string;
|
|
37
|
+
/**
|
|
38
|
+
* Validate the given Tron address.
|
|
39
|
+
* @param {string} address Tron address to validate.
|
|
40
|
+
* @returns {boolean} `true` if the address is valid, `false` otherwise.
|
|
41
|
+
*/
|
|
42
|
+
validateAddress(address: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Get token balance and info directly from contract
|
|
45
|
+
*/
|
|
46
|
+
fetchTokenMetadata: ({ contractAddress }: {
|
|
47
|
+
contractAddress: string;
|
|
48
|
+
}) => Promise<{
|
|
49
|
+
decimals: number;
|
|
50
|
+
symbol: any;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Get token balance and info directly from contract
|
|
54
|
+
*/
|
|
55
|
+
fetchTokenBalance: ({ contractAddress, address }: {
|
|
56
|
+
contractAddress: string;
|
|
57
|
+
address: string;
|
|
58
|
+
}) => Promise<bigint>;
|
|
59
|
+
/**
|
|
60
|
+
* Get current chain parameters including resource prices
|
|
61
|
+
*/
|
|
62
|
+
getChainParameters: () => Promise<{
|
|
63
|
+
bandwidthFee: number;
|
|
64
|
+
createAccountFee: number;
|
|
65
|
+
energyFee: number;
|
|
66
|
+
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Check if an address exists on the blockchain
|
|
69
|
+
*/
|
|
70
|
+
accountExists: (address: string) => Promise<boolean>;
|
|
71
|
+
/**
|
|
72
|
+
* Get account resources (bandwidth and energy)
|
|
73
|
+
*/
|
|
74
|
+
getAccountResources: (address: string) => Promise<{
|
|
75
|
+
bandwidth: {
|
|
76
|
+
free: number;
|
|
77
|
+
total: number;
|
|
78
|
+
used: number;
|
|
79
|
+
};
|
|
80
|
+
energy: {
|
|
81
|
+
total: number;
|
|
82
|
+
used: number;
|
|
83
|
+
};
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* Retrieves the balance of a given address.
|
|
87
|
+
* @param {Address} address - The address to retrieve the balance for.
|
|
88
|
+
* @param {TokenAsset[]} assets - Assets to retrieve the balance for (optional).
|
|
89
|
+
* @returns {Promise<Balance[]>} An array containing the balance of the address.
|
|
90
|
+
*/
|
|
91
|
+
getBalance(address: Address): Promise<Balance[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Get transaction fees.
|
|
94
|
+
* @param {TxParams} params - Tx param
|
|
95
|
+
* @returns {Fees} The average, fast, and fastest fees.
|
|
96
|
+
*/
|
|
97
|
+
getFees(params?: TxParams): Promise<Fees>;
|
|
98
|
+
createTransaction: (params: TxParams) => Promise<import("tronweb/lib/esm/types").Transaction<import("tronweb/lib/esm/types").ContractParamter>>;
|
|
99
|
+
/**
|
|
100
|
+
* Return signed tx
|
|
101
|
+
* @param transaction TronTransaction
|
|
102
|
+
* @param walletIndex wallet index
|
|
103
|
+
* @returns Transaction signed by phrase
|
|
104
|
+
*/
|
|
105
|
+
abstract signTransaction(transaction: TronTransaction, walletIndex?: number): Promise<TronSignedTransaction>;
|
|
106
|
+
/**
|
|
107
|
+
* Transfer TRON Asset
|
|
108
|
+
* @param {TxParams} params The transfer options.
|
|
109
|
+
* @returns {TxHash} The transaction hash.
|
|
110
|
+
*/
|
|
111
|
+
transfer(params: TxParams): Promise<string>;
|
|
112
|
+
/**
|
|
113
|
+
* Check the current allowance for a spender on a token
|
|
114
|
+
*/
|
|
115
|
+
getApprovedAmount: ({ contractAddress, spenderAddress, from }: TronGetApprovedParams) => Promise<bigint>;
|
|
116
|
+
/**
|
|
117
|
+
* Check TRC20 allowance.
|
|
118
|
+
* @param {Address} contractAddress The contract address.
|
|
119
|
+
* @param {Address} spenderAddress The spender address.
|
|
120
|
+
* @param {BaseAmount} amount The amount to check if it's allowed to spend or not (optional).
|
|
121
|
+
* @param {number} walletIndex (optional) HD wallet index
|
|
122
|
+
* @param {IsApprovedParams} params - Parameters for checking allowance.
|
|
123
|
+
* @returns {boolean} `true` if the allowance is approved, `false` otherwise.
|
|
124
|
+
*/
|
|
125
|
+
isApproved({ contractAddress, spenderAddress, amount, walletIndex }: IsApprovedParams): Promise<boolean>;
|
|
126
|
+
/**
|
|
127
|
+
* Approves an allowance for spending tokens.
|
|
128
|
+
*
|
|
129
|
+
* @param {ApproveParams} params - Parameters for approving an allowance.
|
|
130
|
+
* @param {Address} contractAddress The contract address.
|
|
131
|
+
* @param {Address} spenderAddress The spender address.
|
|
132
|
+
* @param {BaseAmount} amount The amount of token. By default, it will be unlimited token allowance. (optional)
|
|
133
|
+
* @param {number} walletIndex (optional) HD wallet index
|
|
134
|
+
* @returns {TransactionResponse} The result of the approval transaction.
|
|
135
|
+
* @throws Error If gas estimation fails.
|
|
136
|
+
*/
|
|
137
|
+
approve({ contractAddress, spenderAddress, amount, walletIndex }: ApproveParams): Promise<string>;
|
|
138
|
+
broadcastTransaction(signedTx: TronSignedTransaction): Promise<TxHash>;
|
|
139
|
+
getTransactions(params?: TxHistoryParams): Promise<TxsPage>;
|
|
140
|
+
/**
|
|
141
|
+
* Get the transaction details of a given transaction ID.
|
|
142
|
+
*
|
|
143
|
+
* @param {string} txId The transaction ID.
|
|
144
|
+
* @returns {Tx} The transaction details.
|
|
145
|
+
*/
|
|
146
|
+
getTransactionData(txId: string): Promise<Tx>;
|
|
147
|
+
broadcastTx(_signedTx: string): Promise<TxHash>;
|
|
148
|
+
prepareTx(_: TxParams & {
|
|
149
|
+
sender: Address;
|
|
150
|
+
}): Promise<PreparedTx>;
|
|
151
|
+
getFeesWithRates(): Promise<FeesWithRates>;
|
|
152
|
+
getFeeRates(): Promise<FeeRate>;
|
|
153
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TronTransaction, TronSignedTransaction, TRONClientParams } from './types';
|
|
2
|
+
import { Client } from './client';
|
|
3
|
+
export declare class ClientKeystore extends Client {
|
|
4
|
+
constructor(params?: TRONClientParams);
|
|
5
|
+
getSigner(walletIndex?: number): {
|
|
6
|
+
getAddress: () => string;
|
|
7
|
+
signTransaction: (transaction: TronTransaction) => Promise<import("tronweb/lib/esm/types").SignedTransaction<import("tronweb/lib/esm/types").ContractParamter> & TronTransaction>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Get the current address synchronously.
|
|
11
|
+
*/
|
|
12
|
+
getAddress(walletIndex?: number): string;
|
|
13
|
+
/**
|
|
14
|
+
* Get the current address asynchronously.
|
|
15
|
+
*
|
|
16
|
+
* @param {number} index The index of the address. Default 0
|
|
17
|
+
* @returns {Address} The TRON address related to the index provided.
|
|
18
|
+
* @throws {"Phrase must be provided"} Thrown if the phrase has not been set before.
|
|
19
|
+
*/
|
|
20
|
+
getAddressAsync(walletIndex?: number): Promise<string>;
|
|
21
|
+
signTransaction(transaction: TronTransaction, walletIndex?: number): Promise<TronSignedTransaction>;
|
|
22
|
+
}
|
package/lib/const.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ExplorerProvider } from '@xchainjs/xchain-client';
|
|
2
|
+
import { Asset, AnyAsset } from '@xchainjs/xchain-util';
|
|
3
|
+
export declare const TRX_DECIMAL = 6;
|
|
4
|
+
export declare const TRON_DERIVATION_PATH = "m/44'/195'/0'/0/";
|
|
5
|
+
/**
|
|
6
|
+
* Chain identifier for Tron mainnet
|
|
7
|
+
*/
|
|
8
|
+
export declare const TRONChain: "TRON";
|
|
9
|
+
export declare const AssetTRX: Asset;
|
|
10
|
+
export declare const AssetTRONUSDT: AnyAsset;
|
|
11
|
+
export declare const TRON_DEFAULT_RPC = "https://tron-rpc.publicnode.com";
|
|
12
|
+
export declare const tronExplorerProviders: {
|
|
13
|
+
mainnet: ExplorerProvider;
|
|
14
|
+
stagenet: ExplorerProvider;
|
|
15
|
+
testnet: ExplorerProvider;
|
|
16
|
+
};
|
|
17
|
+
export declare const TRX_TRANSFER_BANDWIDTH = 268;
|
|
18
|
+
export declare const TRC20_TRANSFER_ENERGY = 13000;
|
|
19
|
+
export declare const TRC20_TRANSFER_BANDWIDTH = 345;
|
|
20
|
+
export declare const TRON_USDT_CONTRACT = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";
|
|
21
|
+
export declare const MAX_APPROVAL = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
|
|
22
|
+
export declare const TRX_FEE_LIMIT = 100000000;
|