| 1 | ## cw_tron |
| 2 | |
| 3 | TRON wallet module for Cake Wallet. Implements TRX and TRC-20 token support on top of `on_chain` (Tron), with transaction history and fee estimation via TronGrid. |
| 4 | |
| 5 | ### Features |
| 6 | |
| 7 | - Connect to TRON nodes over HTTP(S) via `TronProvider`/`TronHTTPProvider`. |
| 8 | - Fetch TRX balance and TRC-20 token balances. |
| 9 | - Estimate fees using bandwidth/energy and memo fee; accounts for available account resources. |
| 10 | - Create and sign TRX and TRC-20 transfers (supports send-all and optional memo). |
| 11 | - Broadcast signed transactions. |
| 12 | - Load account history (TRX and TRC-20), filtering spam and TRC10-only events. |
| 13 | - Manage TRC-20 tokens: add/remove tokens and fetch token metadata. |
| 14 | - Sign/verify messages. |
| 15 | - Node health checks for both native and token balance endpoints. |
| 16 | |
| 17 | ### Getting started |
| 18 | |
| 19 | Provide a TRON RPC endpoint and a TronGrid API key. Add a secrets file: |
| 20 | |
| 21 | ```dart |
| 22 | // cw_tron/lib/.secrets.g.dart (DO NOT COMMIT) |
| 23 | const String tronGridApiKey = 'YOUR_TRONGRID_API_KEY'; |
| 24 | ``` |
| 25 | |
| 26 | Basic connect and sync: |
| 27 | |
| 28 | ```dart |
| 29 | final service = TronWalletService(walletInfoBox, client: TronClient(), isDirect: true); |
| 30 | final wallet = await service.create(TronNewWalletCredentials(name: 'My TRON', password: 'secret')); |
| 31 | await wallet.connectToNode(node: Node(uriRaw: 'api.trongrid.io', isSSL: true)); |
| 32 | await wallet.startSync(); |
| 33 | final trxBalance = wallet.balance[CryptoCurrency.trx]; |
| 34 | ``` |
| 35 | |
| 36 | ### Usage |
| 37 | |
| 38 | Send TRX: |
| 39 | |
| 40 | ```dart |
| 41 | final pending = await wallet.createTransaction( |
| 42 | TronTransactionCredentials.single( |
| 43 | address: 'T...', |
| 44 | cryptoAmount: '1.5', |
| 45 | currency: CryptoCurrency.trx, |
| 46 | ), |
| 47 | ); |
| 48 | final txHash = await pending.commit(); |
| 49 | ``` |
| 50 | |
| 51 | Add USDT (TRC-20): |
| 52 | |
| 53 | ```dart |
| 54 | final usdt = await wallet.getTronToken('TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'); |
| 55 | if (usdt != null) { |
| 56 | await wallet.addTronToken(usdt); |
| 57 | } |
| 58 | ``` |
| 59 | |
| 60 | ### Additional information |
| 61 | |
| 62 | - History and token queries use TronGrid; set `tronGridApiKey`. |
| 63 | - See `lib/` for APIs: `TronClient`, `TronWallet`, `TronWalletService`, and credential types. |