pwc-sdk-wallet 0.7.8 → 0.8.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/README.md CHANGED
@@ -31,6 +31,7 @@ A comprehensive, secure, and user-friendly wallet SDK for React Native applicati
31
31
  - [Account Management](#account-management)
32
32
  - [Add New HD Account](#add-new-hd-account)
33
33
  - [Add New Solana Account](#add-new-solana-account)
34
+ - [Add New TRON Account](#add-new-tron-account)
34
35
  - [Import Account](#import-account)
35
36
  - [Get Accounts](#get-accounts)
36
37
  - [Balance & Token Functions](#balance--token-functions)
@@ -45,6 +46,9 @@ A comprehensive, secure, and user-friendly wallet SDK for React Native applicati
45
46
  - [Send Native Token](#send-native-token)
46
47
  - [Send Token](#send-token)
47
48
  - [Send SPL Token (Solana)](#send-spl-token-solana)
49
+ - [Send TRX (TRON)](#send-trx-tron)
50
+ - [Send TRC-20 Token (TRON)](#send-trc-20-token-tron)
51
+ - [Popular TRON TRC-20 Tokens](#popular-tron-trc-20-tokens)
48
52
  - [Export Mnemonic](#export-mnemonic)
49
53
 
50
54
  ### 🔄 Multi-Transfer Operations
@@ -1469,7 +1473,7 @@ console.log('ERC-1155 transfer gas:', erc1155TransferGas.toString());
1469
1473
 
1470
1474
  - 🔐 **Secure HD Wallet Management**: BIP-44 compliant hierarchical deterministic wallets
1471
1475
  - 🎯 **Vanity Address Generation**: Generate wallets with custom address prefixes
1472
- - 🔗 **Multi-Chain Support**: Ethereum, BSC, Polygon, Arbitrum, Optimism, Base, and Solana
1476
+ - 🔗 **Multi-Chain Support**: Ethereum, BSC, Polygon, Arbitrum, Optimism, Base, Solana, and TRON
1473
1477
  - 🚀 **Multi-Transfer Operations**: Batch send tokens to multiple recipients
1474
1478
  - 🔧 **Custom Chain Support**: Add custom chains and override built-in configurations
1475
1479
  - 📱 **React Native Optimized**: Designed specifically for mobile applications
@@ -1536,6 +1540,13 @@ const { vault, encryptedVault } = await Vault.createFromMnemonic(
1536
1540
  'solana'
1537
1541
  );
1538
1542
 
1543
+ // For TRON
1544
+ const { vault, encryptedVault } = await Vault.createFromMnemonic(
1545
+ existingMnemonic,
1546
+ 'your-secure-password',
1547
+ 'tron'
1548
+ );
1549
+
1539
1550
  // Get wallet accounts
1540
1551
  const accounts = vault.getAccounts();
1541
1552
  console.log('Imported wallet addresses:', accounts.map(acc => acc.address));
@@ -1784,10 +1795,17 @@ console.log('New account address:', newAccount.address);
1784
1795
  #### Add New Solana Account
1785
1796
  ```typescript
1786
1797
  // Add a new Solana account
1787
- const newSolanaAccount = vault.addSolanaAccount();
1798
+ const newSolanaAccount = await vault.addNewSolanaAccount();
1788
1799
  console.log('New Solana account:', newSolanaAccount.address);
1789
1800
  ```
1790
1801
 
1802
+ #### Add New TRON Account
1803
+ ```typescript
1804
+ // Add a new TRON account
1805
+ const newTronAccount = vault.addNewTronAccount();
1806
+ console.log('New TRON account:', newTronAccount.address);
1807
+ ```
1808
+
1791
1809
  #### Import Account
1792
1810
  ```typescript
1793
1811
  // Import an existing account with private key
@@ -1809,6 +1827,14 @@ console.log('All accounts:', accounts.map(acc => acc.address));
1809
1827
  // Get native token balance (ETH, BNB, MATIC, etc.)
1810
1828
  const balance = await vault.getNativeBalance(address, '1'); // Ethereum
1811
1829
  console.log('ETH Balance:', ethers.formatEther(balance));
1830
+
1831
+ // Get SOL balance on Solana
1832
+ const solBalance = await vault.getNativeBalance(address, 'solana');
1833
+ console.log('SOL Balance:', solBalance.toString(), 'lamports');
1834
+
1835
+ // Get TRX balance on TRON
1836
+ const trxBalance = await vault.getNativeBalance(address, 'tron');
1837
+ console.log('TRX Balance:', trxBalance.toString(), 'SUN');
1812
1838
  ```
1813
1839
 
1814
1840
  #### Get Token Balance
@@ -1829,9 +1855,17 @@ console.log('Token:', tokenInfo.name, '(', tokenInfo.symbol, ')');
1829
1855
 
1830
1856
  #### Send Native Token
1831
1857
  ```typescript
1832
- // Send native tokens (ETH, BNB, etc.)
1833
- const tx = await vault.sendNativeToken(from, to, amount, '1');
1858
+ // Send native tokens (ETH, BNB, etc.) on EVM chains
1859
+ const tx = await vault.sendNativeToken(from, to, amount, '1'); // Ethereum
1834
1860
  console.log('Transaction hash:', tx.hash);
1861
+
1862
+ // Send SOL on Solana
1863
+ const solTx = await vault.sendNativeToken(from, to, amount, 'solana');
1864
+ console.log('Solana transaction hash:', solTx.hash);
1865
+
1866
+ // Send TRX on TRON
1867
+ const trxTx = await vault.sendNativeToken(from, to, amount, 'tron');
1868
+ console.log('TRON transaction hash:', trxTx.hash);
1835
1869
  ```
1836
1870
 
1837
1871
  #### Send Token
@@ -1917,6 +1951,96 @@ const USDC_DEVNET = '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU';
1917
1951
  const USDT_DEVNET = 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB';
1918
1952
  ```
1919
1953
 
1954
+ #### Send TRX (TRON)
1955
+ ```typescript
1956
+ // Send native TRX
1957
+ const tx = await vault.sendTRX(from, to, '1.5');
1958
+ console.log('Transaction hash:', tx.hash);
1959
+
1960
+ // Get TRX balance
1961
+ const balance = await vault.getTRXBalance(address);
1962
+ console.log('TRX Balance:', TronChainService.sunToTrx(balance.toString()));
1963
+ ```
1964
+
1965
+ #### Send TRC-20 Token (TRON)
1966
+ ```typescript
1967
+ // Send USDT on TRON
1968
+ const usdtTx = await vault.sendTRC20Token(
1969
+ 'TYourAddress...',
1970
+ 'TRecipient...',
1971
+ '100', // 100 USDT
1972
+ 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t' // USDT contract address
1973
+ );
1974
+
1975
+ // Send USDC on TRON
1976
+ const usdcTx = await vault.sendTRC20Token(
1977
+ 'TYourAddress...',
1978
+ 'TRecipient...',
1979
+ '50', // 50 USDC
1980
+ 'TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8' // USDC contract address
1981
+ );
1982
+
1983
+ // Get TRC-20 token balance
1984
+ const usdtBalance = await vault.getTRC20TokenBalance(
1985
+ 'TYourAddress...',
1986
+ 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'
1987
+ );
1988
+ console.log('USDT Balance:', usdtBalance.toString());
1989
+
1990
+ // Get TRC-20 token information
1991
+ const tokenInfo = await vault.getTRC20TokenInfo(
1992
+ 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'
1993
+ );
1994
+ console.log('Token:', tokenInfo.name, '(', tokenInfo.symbol, ')');
1995
+ console.log('Decimals:', tokenInfo.decimals);
1996
+
1997
+ // Estimate TRX transfer fee
1998
+ const trxFee = await vault.estimateTRXTransferFee(
1999
+ 'TYourAddress...',
2000
+ 'TRecipient...',
2001
+ '1.5'
2002
+ );
2003
+ console.log('Estimated TRX fee:', TronChainService.sunToTrx(trxFee.toString()), 'TRX');
2004
+
2005
+ // Estimate TRC-20 transfer fee
2006
+ const tokenFee = await vault.estimateTRC20TransferFee(
2007
+ 'TYourAddress...',
2008
+ 'TRecipient...',
2009
+ '100',
2010
+ 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'
2011
+ );
2012
+ console.log('Estimated token fee:', TronChainService.sunToTrx(tokenFee.toString()), 'TRX');
2013
+ ```
2014
+
2015
+ #### Popular TRON TRC-20 Tokens
2016
+
2017
+ **Mainnet Token Addresses:**
2018
+ ```typescript
2019
+ // USDT (Tether USD)
2020
+ const USDT_TRC20 = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';
2021
+
2022
+ // USDC (USD Coin)
2023
+ const USDC_TRC20 = 'TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8';
2024
+
2025
+ // USDD (Decentralized USD)
2026
+ const USDD_TRC20 = 'TPYmHEhy5n8TCEfYGqW2rPxsghSfzghPDn';
2027
+
2028
+ // JST (JUST)
2029
+ const JST_TRC20 = 'TCFLL5dx5ZJdKnWuesXxi1VPwjLVmWZZy9';
2030
+
2031
+ // WIN (WINkLink)
2032
+ const WIN_TRC20 = 'TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7';
2033
+ ```
2034
+
2035
+ **Shasta Testnet Token Addresses (for testing):**
2036
+ ```typescript
2037
+ // USDT Shasta
2038
+ const USDT_SHASTA = 'TG3XXyExBkPp9nzdajDZsozEu1kkaAzc3X';
2039
+
2040
+ // USDC Shasta
2041
+ const USDC_SHASTA = 'TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBZ';
2042
+ ```
2043
+
1920
2044
  #### Export Mnemonic
1921
2045
  ```typescript
1922
2046
  // Export the mnemonic phrase (requires password)
@@ -1977,7 +2101,8 @@ console.log('Token transfers completed:', result.successfulCount);
1977
2101
  ```typescript
1978
2102
  import { Vault, type VaultConfig } from 'pwc-wallet-sdk';
1979
2103
 
1980
- const config: VaultConfig = {
2104
+ // Example: EVM chains config
2105
+ const evmConfig: VaultConfig = {
1981
2106
  rpcUrls: {
1982
2107
  '1': 'https://your-eth-rpc.com',
1983
2108
  '56': 'https://your-bsc-rpc.com',
@@ -2002,9 +2127,37 @@ const config: VaultConfig = {
2002
2127
  enableBatchProcessing: true,
2003
2128
  }
2004
2129
  };
2130
+
2131
+ // Example: Solana config
2132
+ const solanaConfig: VaultConfig = {
2133
+ rpcUrls: {
2134
+ 'solana': 'https://your-solana-rpc.com',
2135
+ 'solana-devnet': 'https://your-devnet-rpc.com'
2136
+ },
2137
+ explorerUrls: {
2138
+ 'solana': 'https://solscan.io',
2139
+ 'solana-devnet': 'https://solscan.io?cluster=devnet'
2140
+ },
2141
+ defaultChainId: 'solana'
2142
+ };
2143
+
2144
+ // Example: TRON config
2145
+ const tronConfig: VaultConfig = {
2146
+ rpcUrls: {
2147
+ 'tron': 'https://your-tron-rpc.com',
2148
+ 'tron-shasta': 'https://your-shasta-rpc.com'
2149
+ },
2150
+ explorerUrls: {
2151
+ 'tron': 'https://tronscan.org',
2152
+ 'tron-shasta': 'https://shasta.tronscan.org'
2153
+ },
2154
+ defaultChainId: 'tron'
2155
+ };
2005
2156
  ```
2006
2157
 
2007
2158
  #### Usage Example (Recommended for Mobile Apps)
2159
+
2160
+ **For EVM Chains:**
2008
2161
  ```typescript
2009
2162
  import { Vault, type VaultConfig } from 'pwc-wallet-sdk';
2010
2163
  const appConfig: VaultConfig = {
@@ -2017,12 +2170,63 @@ const appConfig: VaultConfig = {
2017
2170
  const { vault, encryptedVault } = await Vault.createNew(password, 'evm', appConfig);
2018
2171
 
2019
2172
  // Pass config when loading existing vault
2020
- const vault = await Vault.load('password, encryptedVault, appConfig);
2173
+ const vault = await Vault.load(password, encryptedVault, appConfig);
2021
2174
 
2022
2175
  // All operations will use the config automatically
2023
2176
  await vault.sendToken(from, to, amount, tokenAddress, '1');
2024
2177
  ```
2025
2178
 
2179
+ **For Solana:**
2180
+ ```typescript
2181
+ import { Vault, type VaultConfig } from 'pwc-wallet-sdk';
2182
+
2183
+ // Configure Solana RPC URLs
2184
+ const solanaConfig: VaultConfig = {
2185
+ rpcUrls: {
2186
+ 'solana': 'https://your-solana-rpc.com', // Mainnet
2187
+ 'solana-devnet': 'https://your-devnet-rpc.com' // Devnet (optional)
2188
+ },
2189
+ explorerUrls: {
2190
+ 'solana': 'https://solscan.io',
2191
+ 'solana-devnet': 'https://solscan.io?cluster=devnet'
2192
+ },
2193
+ defaultChainId: 'solana' // Optional: set default chain
2194
+ };
2195
+
2196
+ // Create Solana vault with config
2197
+ const { vault, encryptedVault } = await Vault.createNew('password', 'solana', solanaConfig);
2198
+
2199
+ // Or from mnemonic
2200
+ const { vault, encryptedVault } = await Vault.createFromMnemonic(
2201
+ mnemonic,
2202
+ 'password',
2203
+ 'solana',
2204
+ solanaConfig
2205
+ );
2206
+
2207
+ // All Solana operations will use the configured RPC URLs
2208
+ const balance = await vault.getNativeBalance(address, 'solana');
2209
+ const tx = await vault.sendSPLToken(from, to, amount, tokenAddress);
2210
+ ```
2211
+
2212
+ **For TRON:**
2213
+ ```typescript
2214
+ import { Vault, type VaultConfig } from 'pwc-wallet-sdk';
2215
+
2216
+ const tronConfig: VaultConfig = {
2217
+ rpcUrls: {
2218
+ 'tron': 'https://your-tron-rpc.com',
2219
+ 'tron-shasta': 'https://your-shasta-rpc.com' // Testnet (optional)
2220
+ },
2221
+ explorerUrls: {
2222
+ 'tron': 'https://tronscan.org',
2223
+ 'tron-shasta': 'https://shasta.tronscan.org'
2224
+ }
2225
+ };
2226
+
2227
+ const { vault, encryptedVault } = await Vault.createNew('password', 'tron', tronConfig);
2228
+ ```
2229
+
2026
2230
  #### Alternative: Global Config (Advanced)
2027
2231
  You can also set config globally for all vaults:
2028
2232
  ```typescript
package/dist/Vault.d.ts CHANGED
@@ -4,7 +4,7 @@ import { Recipient, MultiTransferResult } from './types/multiTransfer';
4
4
  import { NFTDetailExtended, NFTBalance, NFTOptions } from './types/nft';
5
5
  export interface Account {
6
6
  address: string;
7
- type: 'HD' | 'Simple' | 'Solana';
7
+ type: 'HD' | 'Simple' | 'Solana' | 'Tron';
8
8
  name: string;
9
9
  }
10
10
  export interface TransactionResponse {
@@ -51,11 +51,11 @@ export declare class Vault {
51
51
  /**
52
52
  * Creates a new Vault with a fresh mnemonic.
53
53
  * @param password - The password used to encrypt the vault data
54
- * @param chainType - The type of blockchain to support ('evm' for Ethereum-compatible chains or 'solana' for Solana). Defaults to 'evm'
54
+ * @param chainType - The type of blockchain to support ('evm' for Ethereum-compatible chains, 'solana' for Solana, or 'tron' for TRON). Defaults to 'evm'
55
55
  * @returns Promise resolving to an object containing the created vault instance and its encrypted data
56
56
  * @throws Error if mnemonic generation or keyring initialization fails
57
57
  */
58
- static createNew(password: string, chainType?: 'evm' | 'solana', config?: VaultConfig): Promise<{
58
+ static createNew(password: string, chainType?: 'evm' | 'solana' | 'tron', config?: VaultConfig): Promise<{
59
59
  vault: Vault;
60
60
  encryptedVault: EncryptedData;
61
61
  }>;
@@ -63,11 +63,11 @@ export declare class Vault {
63
63
  * Creates a new Vault from an existing mnemonic phrase.
64
64
  * @param mnemonic - The existing mnemonic phrase (12, 15, 18, 21, or 24 words)
65
65
  * @param password - The password used to encrypt the vault data
66
- * @param chainType - The type of blockchain to support ('evm' for Ethereum-compatible chains or 'solana' for Solana). Defaults to 'evm'
66
+ * @param chainType - The type of blockchain to support ('evm' for Ethereum-compatible chains, 'solana' for Solana, or 'tron' for TRON). Defaults to 'evm'
67
67
  * @returns Promise resolving to an object containing the created vault instance and its encrypted data
68
68
  * @throws Error if mnemonic is invalid or keyring initialization fails
69
69
  */
70
- static createFromMnemonic(mnemonic: string, password: string, chainType?: 'evm' | 'solana', config?: VaultConfig): Promise<{
70
+ static createFromMnemonic(mnemonic: string, password: string, chainType?: 'evm' | 'solana' | 'tron', config?: VaultConfig): Promise<{
71
71
  vault: Vault;
72
72
  encryptedVault: EncryptedData;
73
73
  }>;
@@ -91,6 +91,12 @@ export declare class Vault {
91
91
  * @throws Error if no Solana keyring is available in the vault
92
92
  */
93
93
  addNewSolanaAccount(): Promise<Account>;
94
+ /**
95
+ * Adds a new TRON account derived from the TRON keyring.
96
+ * @returns Promise resolving to the newly created TRON account information
97
+ * @throws Error if no TRON keyring is available in the vault
98
+ */
99
+ addNewTronAccount(): Promise<Account>;
94
100
  /**
95
101
  * Imports an account from a private key and adds it to the vault.
96
102
  * @param privateKey - The private key to import (hex string without '0x' prefix for EVM, base58 for Solana)
@@ -130,6 +136,14 @@ export declare class Vault {
130
136
  * @throws Error if the address is not found in any keyring
131
137
  */
132
138
  getPrivateKeyFor(address: string): Promise<string>;
139
+ /**
140
+ * Gets the native token balance (ETH, SOL, TRX, etc.) for a specific address.
141
+ * @param address - The account address to check balance for
142
+ * @param chainId - The ID of the blockchain (e.g., '1' for Ethereum, 'solana' for Solana, 'tron' for TRON)
143
+ * @returns Promise resolving to the native token balance as a bigint
144
+ * @throws Error if the balance query fails or chain configuration not found
145
+ */
146
+ getNativeBalance(address: string, chainId: ChainId): Promise<bigint>;
133
147
  /**
134
148
  * Gets the token balance for a specific account and token contract.
135
149
  * @param accountAddress - The account address to check balance for
@@ -580,4 +594,82 @@ export declare class Vault {
580
594
  * ```
581
595
  */
582
596
  sendNativeToken(fromAddress: string, to: string, amount: string, chainId: ChainId): Promise<TransactionResponse>;
597
+ /**
598
+ * Sends TRX (native TRON token) to another address.
599
+ * @param fromAddress - The sender's TRON address
600
+ * @param to - The recipient's TRON address
601
+ * @param amount - The amount of TRX to send as a string (e.g., "1.5")
602
+ * @returns Promise resolving to the transaction response with hash and details
603
+ * @throws Error if the transaction fails or recipient address is invalid
604
+ *
605
+ * @example
606
+ * ```typescript
607
+ * // Send 1.5 TRX
608
+ * const tx = await vault.sendTRX(from, to, '1.5');
609
+ * console.log('Transaction hash:', tx.hash);
610
+ * ```
611
+ */
612
+ sendTRX(fromAddress: string, to: string, amount: string): Promise<TransactionResponse>;
613
+ /**
614
+ * Sends TRC-20 tokens on TRON blockchain.
615
+ * @param fromAddress - The sender's TRON address
616
+ * @param to - The recipient's TRON address
617
+ * @param amount - The amount of tokens to send as a string
618
+ * @param tokenAddress - The TRC-20 token contract address
619
+ * @returns Promise resolving to the transaction response with hash and details
620
+ * @throws Error if insufficient balance, invalid addresses, or transaction fails
621
+ *
622
+ * @example
623
+ * ```typescript
624
+ * // Send USDT on TRON
625
+ * const tx = await vault.sendTRC20Token(
626
+ * 'TYourAddress...',
627
+ * 'TRecipient...',
628
+ * '100', // 100 USDT
629
+ * 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t' // USDT contract address
630
+ * );
631
+ * ```
632
+ */
633
+ sendTRC20Token(fromAddress: string, to: string, amount: string, tokenAddress: string): Promise<TransactionResponse>;
634
+ /**
635
+ * Gets TRX balance for a specific address on TRON.
636
+ * @param address - The TRON address to check balance for
637
+ * @returns Promise resolving to the TRX balance as a bigint in SUN
638
+ * @throws Error if the balance query fails
639
+ */
640
+ getTRXBalance(address: string): Promise<bigint>;
641
+ /**
642
+ * Gets TRC-20 token balance for a specific address on TRON.
643
+ * @param address - The TRON address to check balance for
644
+ * @param tokenAddress - The TRC-20 token contract address
645
+ * @returns Promise resolving to the token balance as a bigint
646
+ * @throws Error if the balance query fails
647
+ */
648
+ getTRC20TokenBalance(address: string, tokenAddress: string): Promise<bigint>;
649
+ /**
650
+ * Gets TRC-20 token information.
651
+ * @param tokenAddress - The TRC-20 token contract address
652
+ * @returns Promise resolving to the token information
653
+ * @throws Error if the token query fails
654
+ */
655
+ getTRC20TokenInfo(tokenAddress: string): Promise<Token>;
656
+ /**
657
+ * Estimates the transaction fee for a TRX transfer.
658
+ * @param fromAddress - The sender's TRON address
659
+ * @param to - The recipient's TRON address
660
+ * @param amount - The amount of TRX to send
661
+ * @returns Promise resolving to the estimated fee in SUN
662
+ * @throws Error if the estimation fails
663
+ */
664
+ estimateTRXTransferFee(fromAddress: string, to: string, amount: string): Promise<bigint>;
665
+ /**
666
+ * Estimates the transaction fee for a TRC-20 token transfer.
667
+ * @param fromAddress - The sender's TRON address
668
+ * @param to - The recipient's TRON address
669
+ * @param amount - The amount of tokens to send
670
+ * @param tokenAddress - The TRC-20 token contract address
671
+ * @returns Promise resolving to the estimated fee in SUN
672
+ * @throws Error if the estimation fails
673
+ */
674
+ estimateTRC20TransferFee(fromAddress: string, to: string, amount: string, tokenAddress: string): Promise<bigint>;
583
675
  }