@bankofai/mcp-server-tron 1.1.3 → 1.1.5
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 +56 -73
- package/build/core/prompts.js +1 -2
- package/build/core/prompts.js.map +1 -1
- package/build/core/services/account-resource.d.ts +56 -0
- package/build/core/services/account-resource.js +133 -0
- package/build/core/services/account-resource.js.map +1 -0
- package/build/core/services/account.d.ts +7 -11
- package/build/core/services/account.js +25 -41
- package/build/core/services/account.js.map +1 -1
- package/build/core/services/accountResource.d.ts +2 -2
- package/build/core/services/accountResource.js +11 -30
- package/build/core/services/accountResource.js.map +1 -1
- package/build/core/services/agent-wallet.d.ts +65 -0
- package/build/core/services/agent-wallet.js +196 -0
- package/build/core/services/agent-wallet.js.map +1 -0
- package/build/core/services/clients.d.ts +0 -4
- package/build/core/services/clients.js +0 -17
- package/build/core/services/clients.js.map +1 -1
- package/build/core/services/contracts.d.ts +9 -8
- package/build/core/services/contracts.js +53 -53
- package/build/core/services/contracts.js.map +1 -1
- package/build/core/services/governance.d.ts +5 -10
- package/build/core/services/governance.js +31 -63
- package/build/core/services/governance.js.map +1 -1
- package/build/core/services/index.d.ts +2 -1
- package/build/core/services/index.js +5 -2
- package/build/core/services/index.js.map +1 -1
- package/build/core/services/proposals.d.ts +3 -6
- package/build/core/services/proposals.js +17 -40
- package/build/core/services/proposals.js.map +1 -1
- package/build/core/services/staking.d.ts +4 -20
- package/build/core/services/staking.js +24 -64
- package/build/core/services/staking.js.map +1 -1
- package/build/core/services/transfer.d.ts +4 -4
- package/build/core/services/transfer.js +40 -26
- package/build/core/services/transfer.js.map +1 -1
- package/build/core/services/wallet.d.ts +5 -29
- package/build/core/services/wallet.js +7 -108
- package/build/core/services/wallet.js.map +1 -1
- package/build/core/tools/account-resource.js +14 -12
- package/build/core/tools/account-resource.js.map +1 -1
- package/build/core/tools/account.js +7 -15
- package/build/core/tools/account.js.map +1 -1
- package/build/core/tools/broadcast.js +1 -1
- package/build/core/tools/broadcast.js.map +1 -1
- package/build/core/tools/contract.js +11 -16
- package/build/core/tools/contract.js.map +1 -1
- package/build/core/tools/governance.js +10 -15
- package/build/core/tools/governance.js.map +1 -1
- package/build/core/tools/index.js +1 -2
- package/build/core/tools/index.js.map +1 -1
- package/build/core/tools/proposals.js +6 -9
- package/build/core/tools/proposals.js.map +1 -1
- package/build/core/tools/staking.js +10 -14
- package/build/core/tools/staking.js.map +1 -1
- package/build/core/tools/transfer.js +6 -8
- package/build/core/tools/transfer.js.map +1 -1
- package/build/core/tools/wallet.js +87 -2
- package/build/core/tools/wallet.js.map +1 -1
- package/build/server/http-server.js +7 -8
- package/build/server/http-server.js.map +1 -1
- package/build/server/server.d.ts +3 -0
- package/build/server/server.js +4 -2
- package/build/server/server.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ Key capabilities:
|
|
|
36
36
|
- **Smart Contracts**: Interact with any TRON smart contract (Read/Write).
|
|
37
37
|
- **Tokens**: Transfer TRX and TRC20 tokens; check balances.
|
|
38
38
|
- **Address Management**: Convert between Hex (0x...) and Base58 (T...) formats.
|
|
39
|
-
- **Wallet Integration**:
|
|
39
|
+
- **Wallet Integration**: Agent-wallet (encrypted keystore), Private Key, and Mnemonic (BIP-39) wallets.
|
|
40
40
|
- **Multi-Network**: Seamless support for Mainnet, Nile, and Shasta.
|
|
41
41
|
- **Dynamic Access Control**: Automatically hides write tools if no wallet is configured or if `--readonly` mode is active.
|
|
42
42
|
|
|
@@ -91,9 +91,10 @@ Key capabilities:
|
|
|
91
91
|
|
|
92
92
|
### Wallet & Security
|
|
93
93
|
|
|
94
|
-
- **
|
|
94
|
+
- **Agent Wallet (Recommended)**: Encrypted key storage via agent-wallet SDK — private keys never leave the keystore.
|
|
95
|
+
- **Static Wallet**: Configure via `TRON_PRIVATE_KEY` or `TRON_MNEMONIC` environment variables.
|
|
95
96
|
- **HD Wallet**: Supports BIP-44 derivation path `m/44'/195'/0'/0/{index}`.
|
|
96
|
-
- **Signing**: Sign arbitrary messages.
|
|
97
|
+
- **Signing**: Sign arbitrary messages and transactions.
|
|
97
98
|
|
|
98
99
|
## Supported Networks
|
|
99
100
|
|
|
@@ -110,7 +111,7 @@ Key capabilities:
|
|
|
110
111
|
|
|
111
112
|
```bash
|
|
112
113
|
# Clone the repository
|
|
113
|
-
git clone https://github.com/
|
|
114
|
+
git clone https://github.com/BofAI/mcp-server-tron.git
|
|
114
115
|
cd mcp-server-tron
|
|
115
116
|
|
|
116
117
|
# Install dependencies
|
|
@@ -134,23 +135,40 @@ To enable write operations (transfers, contract calls) and ensure reliable API a
|
|
|
134
135
|
export TRONGRID_API_KEY="<YOUR_TRONGRID_API_KEY_HERE>"
|
|
135
136
|
```
|
|
136
137
|
|
|
137
|
-
#### Wallet Configuration
|
|
138
|
+
#### Wallet Configuration
|
|
138
139
|
|
|
139
|
-
**
|
|
140
|
+
Choose **one** of the following modes. If none is configured, the server runs in **read-only mode**.
|
|
141
|
+
|
|
142
|
+
**Option 1: Agent-Wallet Mode (Recommended)**
|
|
143
|
+
|
|
144
|
+
Private keys are encrypted at rest and never exposed in environment variables.
|
|
145
|
+
|
|
146
|
+
> **Prerequisites**: Install and configure [agent-wallet](https://github.com/BofAI/agent-wallet/blob/main/doc/getting-started.md)
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
export AGENT_WALLET_PASSWORD="<YOUR_MASTER_PASSWORD>"
|
|
150
|
+
export AGENT_WALLET_DIR="<YOUR_WALLET_DIR>" # Optional, default: ~/.agent-wallet
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
> `AGENT_WALLET_PASSWORD` must match the master password used during `agent-wallet`. If not set, agent-wallet mode is disabled and the server falls back to static mode or read-only mode.
|
|
154
|
+
|
|
155
|
+
**Option 2: Private Key**
|
|
140
156
|
|
|
141
157
|
```bash
|
|
142
|
-
# Recommended: Add this to your ~/.zshrc or ~/.bashrc
|
|
143
158
|
export TRON_PRIVATE_KEY="<YOUR_PRIVATE_KEY_HERE>"
|
|
144
159
|
```
|
|
145
160
|
|
|
146
|
-
**Option
|
|
161
|
+
**Option 3: Mnemonic Phrase**
|
|
147
162
|
|
|
148
163
|
```bash
|
|
149
|
-
# Recommended: Add this to your ~/.zshrc or ~/.bashrc
|
|
150
164
|
export TRON_MNEMONIC="<WORD1> <WORD2> ... <WORD12>"
|
|
151
|
-
export TRON_ACCOUNT_INDEX="0"
|
|
165
|
+
export TRON_ACCOUNT_INDEX="0" # Optional, default: 0
|
|
152
166
|
```
|
|
153
167
|
|
|
168
|
+
> **Security Note**: Static modes store keys in plaintext environment variables. Agent-wallet mode is strongly recommended for production use.
|
|
169
|
+
|
|
170
|
+
> See [`.env.example`](.env.example) for a complete list of all supported environment variables.
|
|
171
|
+
|
|
154
172
|
### Server Configuration
|
|
155
173
|
|
|
156
174
|
The server runs on port **3001** by default in HTTP mode.
|
|
@@ -166,7 +184,7 @@ npm start
|
|
|
166
184
|
# Start in readonly mode (disables write tools)
|
|
167
185
|
npm start -- --readonly
|
|
168
186
|
|
|
169
|
-
# Start in HTTP mode (
|
|
187
|
+
# Start in HTTP mode (Streamable HTTP)
|
|
170
188
|
npm run start:http
|
|
171
189
|
```
|
|
172
190
|
|
|
@@ -181,65 +199,46 @@ npm test
|
|
|
181
199
|
# Unit tests (mocked services, no network)
|
|
182
200
|
npx vitest tests/core/tools.test.ts # All MCP tools registration & handlers
|
|
183
201
|
npx vitest tests/core/services/contracts.test.ts # Contract services
|
|
184
|
-
npx vitest tests/core/services/
|
|
202
|
+
npx vitest tests/core/services/account-resource.test.ts # Account resource services
|
|
185
203
|
npx vitest tests/core/services/staking.test.ts # Staking services
|
|
186
204
|
|
|
187
|
-
# Integration tests (real Nile RPC; write tests require TRON_PRIVATE_KEY)
|
|
205
|
+
# Integration tests (real Nile RPC; write tests require AGENT_WALLET_PASSWORD or TRON_PRIVATE_KEY)
|
|
188
206
|
npx vitest tests/core/tools_integration.test.ts # Full tool flow on Nile
|
|
189
207
|
npx vitest tests/core/services/multicall.test.ts # Multicall integration
|
|
190
208
|
npx vitest tests/core/services/services.test.ts # Services integration
|
|
191
209
|
```
|
|
192
210
|
|
|
193
211
|
- **Unit tests** use mocks and do not need network or wallet.
|
|
194
|
-
- **Integration tests** (`tools_integration.test.ts`) call Nile RPC; most cases are read-only. Tests that broadcast transactions (e.g. `vote_witness`, `withdraw_balance`) run only when
|
|
212
|
+
- **Integration tests** (`tools_integration.test.ts`) call Nile RPC; most cases are read-only. Tests that broadcast transactions (e.g. `vote_witness`, `withdraw_balance`) run only when a wallet is configured (`AGENT_WALLET_PASSWORD` or `TRON_PRIVATE_KEY`) and are skipped otherwise.
|
|
195
213
|
|
|
196
214
|
### Client Configuration
|
|
197
215
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
#### 1. Locate your Configuration File
|
|
216
|
+
#### Option A: Quick Start (Recommended)
|
|
201
217
|
|
|
202
|
-
|
|
203
|
-
| :--------------------- | :------ | :---------------------------------------------------------------- |
|
|
204
|
-
| **Claude Desktop** | macOS | `~/Library/Application Support/Claude/claude_desktop_config.json` |
|
|
205
|
-
| | Windows | `%APPDATA%\Claude\claude_desktop_config.json` |
|
|
206
|
-
| **Cursor** | All | Project root: `.cursor/mcp.json` |
|
|
207
|
-
| **Google Antigravity** | All | `~/.config/antigravity/mcp.json` |
|
|
208
|
-
| **Opencode** | All | `~/.config/opencode/mcp.json` |
|
|
218
|
+
Runs the latest version directly from npm via stdio transport.
|
|
209
219
|
|
|
210
|
-
|
|
220
|
+
**Claude Code:**
|
|
211
221
|
|
|
212
|
-
|
|
222
|
+
```bash
|
|
223
|
+
claude mcp add mcp-server-tron -- npx -y @bankofai/mcp-server-tron
|
|
224
|
+
```
|
|
213
225
|
|
|
214
|
-
|
|
215
|
-
Runs the latest version directly from npm.
|
|
226
|
+
With environment variables:
|
|
216
227
|
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
"mcpServers": {
|
|
220
|
-
"mcp-server-tron": {
|
|
221
|
-
"command": "npx",
|
|
222
|
-
"args": ["-y", "@bankofai/mcp-server-tron"],
|
|
223
|
-
"env": {
|
|
224
|
-
"TRON_PRIVATE_KEY": "YOUR_KEY_HERE (Or set in system env)",
|
|
225
|
-
"TRONGRID_API_KEY": "YOUR_KEY_HERE (Or set in system env)"
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
228
|
+
```bash
|
|
229
|
+
claude mcp add -e AGENT_WALLET_PASSWORD=xxx -e TRONGRID_API_KEY=xxx mcp-server-tron -- npx -y @bankofai/mcp-server-tron
|
|
230
230
|
```
|
|
231
231
|
|
|
232
|
-
**
|
|
233
|
-
For developers running from the cloned repository.
|
|
232
|
+
**Cursor** (`.cursor/mcp.json`):
|
|
234
233
|
|
|
235
234
|
```json
|
|
236
235
|
{
|
|
237
236
|
"mcpServers": {
|
|
238
237
|
"mcp-server-tron": {
|
|
239
238
|
"command": "npx",
|
|
240
|
-
"args": ["
|
|
239
|
+
"args": ["-y", "@bankofai/mcp-server-tron"],
|
|
241
240
|
"env": {
|
|
242
|
-
"
|
|
241
|
+
"AGENT_WALLET_PASSWORD": "YOUR_PASSWORD (Or set in system env)",
|
|
243
242
|
"TRONGRID_API_KEY": "YOUR_KEY_HERE (Or set in system env)"
|
|
244
243
|
}
|
|
245
244
|
}
|
|
@@ -247,48 +246,28 @@ For developers running from the cloned repository.
|
|
|
247
246
|
}
|
|
248
247
|
```
|
|
249
248
|
|
|
250
|
-
|
|
251
|
-
Connect to the official hosted server at `https://mcp-server.bankofai.io`. No installation required, readonly mode.
|
|
249
|
+
#### Option B: Official Hosted Server (Remote)
|
|
252
250
|
|
|
253
|
-
|
|
251
|
+
Connect to the official hosted server at `https://tron-mcp-server.bankofai.io`. No installation required, readonly mode.
|
|
254
252
|
|
|
255
|
-
|
|
256
|
-
{
|
|
257
|
-
"mcpServers": {
|
|
258
|
-
"mcp-server-tron": {
|
|
259
|
-
"url": "https://mcp-server.bankofai.io/mcp"
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
```
|
|
253
|
+
**Claude Code:**
|
|
264
254
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
```json
|
|
268
|
-
{
|
|
269
|
-
"mcpServers": {
|
|
270
|
-
"mcp-server-tron": {
|
|
271
|
-
"serverUrl": "https://mcp-server.bankofai.io/mcp"
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
255
|
+
```bash
|
|
256
|
+
claude mcp add -transport http mcp-server-tron https://tron-mcp-server.bankofai.io/mcp
|
|
275
257
|
```
|
|
276
258
|
|
|
277
|
-
|
|
259
|
+
**Cursor** (`.cursor/mcp.json`):
|
|
278
260
|
|
|
279
261
|
```json
|
|
280
262
|
{
|
|
281
|
-
"
|
|
263
|
+
"mcpServers": {
|
|
282
264
|
"mcp-server-tron": {
|
|
283
|
-
"
|
|
284
|
-
"url": "https://mcp-server.bankofai.io/mcp"
|
|
265
|
+
"url": "https://tron-mcp-server.bankofai.io/mcp"
|
|
285
266
|
}
|
|
286
267
|
}
|
|
287
268
|
}
|
|
288
269
|
```
|
|
289
270
|
|
|
290
|
-
**Important**: We recommend omitting the `env` section if you have already set these variables in your system environment. If your MCP client doesn't inherit system variables, use placeholders or ensure the config file is not shared or committed to version control.
|
|
291
|
-
|
|
292
271
|
## API Reference
|
|
293
272
|
|
|
294
273
|
### Tools
|
|
@@ -298,6 +277,8 @@ Opencode:
|
|
|
298
277
|
| Tool Name | Description | Key Parameters |
|
|
299
278
|
| :------------------- | :-------------------------------------------------- | :------------- |
|
|
300
279
|
| `get_wallet_address` | Get the configured wallet's address (Base58 & Hex). | - |
|
|
280
|
+
| `list_wallets` | List all available wallets with IDs and addresses. | - |
|
|
281
|
+
| `select_wallet` | Switch the active wallet at runtime (agent-wallet mode). | `walletId` |
|
|
301
282
|
| `convert_address` | Convert between Hex and Base58 formats. | `address` |
|
|
302
283
|
|
|
303
284
|
#### Network & Resources
|
|
@@ -481,7 +462,9 @@ Opencode:
|
|
|
481
462
|
### Prompts
|
|
482
463
|
|
|
483
464
|
- `prepare_transfer`: Interactive guide to prepare TRX/TRC20 transfers.
|
|
465
|
+
- `interact_with_contract`: Step-by-step guide to interact with a smart contract.
|
|
484
466
|
- `diagnose_transaction`: Analyze a transaction hash for status and errors.
|
|
467
|
+
- `explain_tron_concept`: Explain a TRON blockchain concept with examples.
|
|
485
468
|
- `analyze_wallet`: Comprehensive report of wallet assets.
|
|
486
469
|
- `check_network_status`: Report on network health and resource costs.
|
|
487
470
|
|
package/build/core/prompts.js
CHANGED
|
@@ -16,7 +16,6 @@ import * as services from "./services/index.js";
|
|
|
16
16
|
* @param options Registration options
|
|
17
17
|
*/
|
|
18
18
|
export function registerTRONPrompts(server, options = {}) {
|
|
19
|
-
const { isWalletConfigured } = services;
|
|
20
19
|
/**
|
|
21
20
|
* Helper to register a prompt with automatic wallet requirement detection.
|
|
22
21
|
* Prompts that guide write operations should only be registered if a wallet
|
|
@@ -33,7 +32,7 @@ export function registerTRONPrompts(server, options = {}) {
|
|
|
33
32
|
return;
|
|
34
33
|
}
|
|
35
34
|
// 2. Skip if the prompt needs a wallet but none is configured
|
|
36
|
-
if (walletNeeded &&
|
|
35
|
+
if (walletNeeded && services.getActiveWalletId() === null) {
|
|
37
36
|
return;
|
|
38
37
|
}
|
|
39
38
|
server.registerPrompt(name, definition, handler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/core/prompts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAEhD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAiB,EAAE,UAAkC,EAAE;IACzF
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/core/promp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EAAE,6CAA6C;QAC1D,UAAU,EAAE;YACV,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;SAC3E;KACF,EACD,CAAC,EAAE,OAAO,GAAG,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;QAC5B,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE;oBACP,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE;;yDAEuC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;2BA2BrC,OAAO;;;;;;;;;;;;;;;;CAgBjC;iBACU;aACF;SACF;KACF,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delegate staked resources (BANDWIDTH or ENERGY) to another address.
|
|
3
|
+
* Wraps TronWeb's transactionBuilder.delegateResource.
|
|
4
|
+
*/
|
|
5
|
+
export declare function delegateResource(params: {
|
|
6
|
+
amount: number;
|
|
7
|
+
receiverAddress: string;
|
|
8
|
+
resource: "BANDWIDTH" | "ENERGY";
|
|
9
|
+
lock?: boolean;
|
|
10
|
+
lockPeriod?: number;
|
|
11
|
+
}, network?: string): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Revoke delegated resources (BANDWIDTH or ENERGY) from a receiver address.
|
|
14
|
+
* Wraps TronWeb's transactionBuilder.undelegateResource.
|
|
15
|
+
*/
|
|
16
|
+
export declare function undelegateResource(params: {
|
|
17
|
+
amount: number;
|
|
18
|
+
receiverAddress: string;
|
|
19
|
+
resource: "BANDWIDTH" | "ENERGY";
|
|
20
|
+
}, network?: string): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Get the maximum amount of resources that can currently be delegated by an address.
|
|
23
|
+
* Wraps TronWeb's trx.getCanDelegatedMaxSize / walletsolidity.getcandelegatedmaxsize.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getCanDelegatedMaxSize(address: string, resource: "BANDWIDTH" | "ENERGY", network?: string): Promise<{
|
|
26
|
+
address: string;
|
|
27
|
+
resource: "BANDWIDTH" | "ENERGY";
|
|
28
|
+
maxSizeSun: bigint;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Get delegated resource details between two addresses under Stake 2.0.
|
|
32
|
+
* Wraps TronWeb's trx.getDelegatedResourceV2 / wallet.getdelegatedresourcev2.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getDelegatedResourceV2(fromAddress: string, toAddress: string, network?: string): Promise<{
|
|
35
|
+
from: string;
|
|
36
|
+
to: string;
|
|
37
|
+
delegatedResource: {
|
|
38
|
+
from: any;
|
|
39
|
+
to: any;
|
|
40
|
+
frozenBalanceForBandwidthSun: string;
|
|
41
|
+
frozenBalanceForEnergySun: string;
|
|
42
|
+
expireTimeForBandwidth: any;
|
|
43
|
+
expireTimeForEnergy: any;
|
|
44
|
+
}[];
|
|
45
|
+
raw: any;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Get delegated resource account index for an address under Stake 2.0.
|
|
49
|
+
* Wraps walletsolidity.getdelegatedresourceaccountindexv2.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getDelegatedResourceAccountIndexV2(address: string, network?: string): Promise<{
|
|
52
|
+
account: any;
|
|
53
|
+
fromAccounts: any;
|
|
54
|
+
toAccounts: any;
|
|
55
|
+
raw: unknown;
|
|
56
|
+
}>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { getTronWeb } from "./clients.js";
|
|
2
|
+
import { getOwnerAddress, buildSignBroadcast } from "./agent-wallet.js";
|
|
3
|
+
/**
|
|
4
|
+
* Delegate staked resources (BANDWIDTH or ENERGY) to another address.
|
|
5
|
+
* Wraps TronWeb's transactionBuilder.delegateResource.
|
|
6
|
+
*/
|
|
7
|
+
export async function delegateResource(params, network = "mainnet") {
|
|
8
|
+
const tronWeb = getTronWeb(network);
|
|
9
|
+
const ownerAddress = await getOwnerAddress();
|
|
10
|
+
try {
|
|
11
|
+
const { amount, receiverAddress, resource, lock = false, lockPeriod = 0 } = params;
|
|
12
|
+
const tx = await tronWeb.transactionBuilder.delegateResource(amount, receiverAddress, resource, ownerAddress, lock, lockPeriod, {});
|
|
13
|
+
return await buildSignBroadcast(tx, network);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
throw new Error(`Failed to delegate resource: ${error.message}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Revoke delegated resources (BANDWIDTH or ENERGY) from a receiver address.
|
|
21
|
+
* Wraps TronWeb's transactionBuilder.undelegateResource.
|
|
22
|
+
*/
|
|
23
|
+
export async function undelegateResource(params, network = "mainnet") {
|
|
24
|
+
const tronWeb = getTronWeb(network);
|
|
25
|
+
const ownerAddress = await getOwnerAddress();
|
|
26
|
+
try {
|
|
27
|
+
const { amount, receiverAddress, resource } = params;
|
|
28
|
+
const tx = await tronWeb.transactionBuilder.undelegateResource(amount, receiverAddress, resource, ownerAddress, {});
|
|
29
|
+
return await buildSignBroadcast(tx, network);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new Error(`Failed to undelegate resource: ${error.message}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the maximum amount of resources that can currently be delegated by an address.
|
|
37
|
+
* Wraps TronWeb's trx.getCanDelegatedMaxSize / walletsolidity.getcandelegatedmaxsize.
|
|
38
|
+
*/
|
|
39
|
+
export async function getCanDelegatedMaxSize(address, resource, network = "mainnet") {
|
|
40
|
+
const tronWeb = getTronWeb(network);
|
|
41
|
+
try {
|
|
42
|
+
// Prefer TronWeb helper if available
|
|
43
|
+
const type = resource === "ENERGY" ? 1 : 0;
|
|
44
|
+
// tronWeb.trx.getCanDelegatedMaxSize(address, resourceType)
|
|
45
|
+
const res = typeof tronWeb.trx.getCanDelegatedMaxSize === "function"
|
|
46
|
+
? await tronWeb.trx.getCanDelegatedMaxSize(address, resource)
|
|
47
|
+
: await tronWeb.fullNode.request("wallet/getcandelegatedmaxsize", {
|
|
48
|
+
owner_address: tronWeb.address.toHex(address),
|
|
49
|
+
type,
|
|
50
|
+
visible: false,
|
|
51
|
+
}, "post");
|
|
52
|
+
const raw = res?.max_size;
|
|
53
|
+
if (raw === undefined || (typeof raw !== "number" && typeof raw !== "string")) {
|
|
54
|
+
throw new Error(`Unexpected response from getCanDelegatedMaxSize: ${JSON.stringify(res)}`);
|
|
55
|
+
}
|
|
56
|
+
const maxSizeSun = BigInt(raw);
|
|
57
|
+
return {
|
|
58
|
+
address,
|
|
59
|
+
resource,
|
|
60
|
+
maxSizeSun,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
throw new Error(`Failed to get can delegated max size: ${error.message}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get delegated resource details between two addresses under Stake 2.0.
|
|
69
|
+
* Wraps TronWeb's trx.getDelegatedResourceV2 / wallet.getdelegatedresourcev2.
|
|
70
|
+
*/
|
|
71
|
+
export async function getDelegatedResourceV2(fromAddress, toAddress, network = "mainnet") {
|
|
72
|
+
const tronWeb = getTronWeb(network);
|
|
73
|
+
try {
|
|
74
|
+
const res = typeof tronWeb.trx.getDelegatedResourceV2 === "function"
|
|
75
|
+
? await tronWeb.trx.getDelegatedResourceV2(fromAddress, toAddress, {
|
|
76
|
+
confirmed: true,
|
|
77
|
+
})
|
|
78
|
+
: await tronWeb.fullNode.request("wallet/getdelegatedresourcev2", {
|
|
79
|
+
fromAddress: tronWeb.address.toHex(fromAddress),
|
|
80
|
+
toAddress: tronWeb.address.toHex(toAddress),
|
|
81
|
+
visible: false,
|
|
82
|
+
}, "post");
|
|
83
|
+
const delegated = res?.delegatedResource || (Array.isArray(res) ? res : []);
|
|
84
|
+
// Normalize numeric fields to BigInt/string form for safety
|
|
85
|
+
const normalized = delegated.map((item) => {
|
|
86
|
+
const bandwidth = item.frozen_balance_for_bandwidth ?? 0;
|
|
87
|
+
const energy = item.frozen_balance_for_energy ?? 0;
|
|
88
|
+
return {
|
|
89
|
+
from: item.from || fromAddress,
|
|
90
|
+
to: item.to || toAddress,
|
|
91
|
+
frozenBalanceForBandwidthSun: BigInt(bandwidth).toString(),
|
|
92
|
+
frozenBalanceForEnergySun: BigInt(energy).toString(),
|
|
93
|
+
expireTimeForBandwidth: item.expire_time_for_bandwidth ?? 0,
|
|
94
|
+
expireTimeForEnergy: item.expire_time_for_energy ?? 0,
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
from: fromAddress,
|
|
99
|
+
to: toAddress,
|
|
100
|
+
delegatedResource: normalized,
|
|
101
|
+
raw: res,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
throw new Error(`Failed to get delegated resource v2: ${error.message}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get delegated resource account index for an address under Stake 2.0.
|
|
110
|
+
* Wraps walletsolidity.getdelegatedresourceaccountindexv2.
|
|
111
|
+
*/
|
|
112
|
+
export async function getDelegatedResourceAccountIndexV2(address, network = "mainnet") {
|
|
113
|
+
const tronWeb = getTronWeb(network);
|
|
114
|
+
try {
|
|
115
|
+
const res = await tronWeb.fullNode.request("wallet/getdelegatedresourceaccountindexv2", {
|
|
116
|
+
value: tronWeb.address.toHex(address),
|
|
117
|
+
visible: false,
|
|
118
|
+
}, "post");
|
|
119
|
+
const account = res?.account ?? address;
|
|
120
|
+
const fromAccounts = res?.fromAccounts ?? [];
|
|
121
|
+
const toAccounts = res?.toAccounts ?? [];
|
|
122
|
+
return {
|
|
123
|
+
account,
|
|
124
|
+
fromAccounts,
|
|
125
|
+
toAccounts,
|
|
126
|
+
raw: res,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
throw new Error(`Failed to get delegated resource account index v2: ${error.message}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=account-resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-resource.js","sourceRoot":"","sources":["../../../src/core/services/account-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAExE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAMC,EACD,OAAO,GAAG,SAAS;IAEnB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,YAAY,GAAG,MAAM,eAAe,EAAE,CAAC;IAE7C,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,IAAI,GAAG,KAAK,EAAE,UAAU,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC;QAEnF,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,kBAAkB,CAAC,gBAAgB,CAC1D,MAAM,EACN,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,EAAE,CACH,CAAC;QACF,OAAO,MAAM,kBAAkB,CAAC,EAAS,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,gCAAgC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAIC,EACD,OAAO,GAAG,SAAS;IAEnB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,YAAY,GAAG,MAAM,eAAe,EAAE,CAAC;IAE7C,IAAI,CAAC;QACH,MA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AAI,GAAW,EAAE,YAAY,IAAI,EAAE,CAAC;QACtD,MAAM,UAAU,GAAI,GAAW,EAAE,UAAU,IAAI,EAAE,CAAC;QAElD,OAAO;YACL,OAAO;YACP,YAAY;YACZ,UAAU;YACV,GAAG,EAAE,GAAG;SACT,CAAC;IACJ,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,sDAAsD,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACzF,CAAC;AACH,CAAC"}
|
|
@@ -18,16 +18,15 @@ export declare function getAccountBalance(address: string, blockHash: string, bl
|
|
|
18
18
|
block_identifier?: any;
|
|
19
19
|
}>;
|
|
20
20
|
/**
|
|
21
|
-
* Generate a new account
|
|
22
|
-
*
|
|
21
|
+
* Generate a new account.
|
|
22
|
+
* Unified interface that returns a new keypair (ephemeral).
|
|
23
23
|
*/
|
|
24
24
|
export declare function generateAccount(): Promise<{
|
|
25
|
-
privateKey: string;
|
|
26
|
-
publicKey: string;
|
|
27
25
|
address: {
|
|
28
26
|
base58: string;
|
|
29
|
-
hex: string;
|
|
30
27
|
};
|
|
28
|
+
privateKey: string;
|
|
29
|
+
message: string;
|
|
31
30
|
}>;
|
|
32
31
|
/**
|
|
33
32
|
* Validate a TRON address
|
|
@@ -85,30 +84,27 @@ export declare function getDelegatedResourceIndex(address: string, network?: str
|
|
|
85
84
|
}>;
|
|
86
85
|
/**
|
|
87
86
|
* Activate a new account on the TRON network (costs bandwidth from the creator)
|
|
88
|
-
* @param privateKey Creator's private key
|
|
89
87
|
* @param newAddress Address to activate
|
|
90
88
|
* @param network Network name
|
|
91
89
|
* @returns Transaction hash
|
|
92
90
|
*/
|
|
93
|
-
export declare function createAccount(
|
|
91
|
+
export declare function createAccount(newAddress: string, network?: string): Promise<string>;
|
|
94
92
|
/**
|
|
95
93
|
* Update account name (can only be set once)
|
|
96
|
-
* @param privateKey Account's private key
|
|
97
94
|
* @param accountName New account name
|
|
98
95
|
* @param network Network name
|
|
99
96
|
* @returns Transaction hash
|
|
100
97
|
*/
|
|
101
|
-
export declare function updateAccount(
|
|
98
|
+
export declare function updateAccount(accountName: string, network?: string): Promise<string>;
|
|
102
99
|
/**
|
|
103
100
|
* Update account permissions (multi-signature configuration)
|
|
104
|
-
* @param privateKey Account's private key
|
|
105
101
|
* @param ownerPermission Owner permission configuration
|
|
106
102
|
* @param activePermissions Active permission(s) configuration
|
|
107
103
|
* @param witnessPermission Optional witness permission (for Super Representatives)
|
|
108
104
|
* @param network Network name
|
|
109
105
|
* @returns Transaction hash
|
|
110
106
|
*/
|
|
111
|
-
export declare function updateAccountPermissions(
|
|
107
|
+
export declare function updateAccountPermissions(ownerPermission: {
|
|
112
108
|
type: number;
|
|
113
109
|
permission_name: string;
|
|
114
110
|
threshold: number;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TronWeb } from "tronweb";
|
|
2
|
-
import { getTronWeb
|
|
2
|
+
import { getTronWeb } from "./clients.js";
|
|
3
|
+
import { getOwnerAddress, buildSignBroadcast, generateAccountKeypair as generateAccountService, } from "./agent-wallet.js";
|
|
3
4
|
/**
|
|
4
5
|
* Get full account information from the TRON network
|
|
5
6
|
* @param address Account address (Base58 or Hex)
|
|
@@ -39,13 +40,17 @@ export async function getAccountBalance(address, blockHash, blockNumber, network
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
/**
|
|
42
|
-
* Generate a new account
|
|
43
|
-
*
|
|
43
|
+
* Generate a new account.
|
|
44
|
+
* Unified interface that returns a new keypair (ephemeral).
|
|
44
45
|
*/
|
|
45
46
|
export async function generateAccount() {
|
|
46
47
|
try {
|
|
47
|
-
const
|
|
48
|
-
return
|
|
48
|
+
const result = await generateAccountService();
|
|
49
|
+
return {
|
|
50
|
+
address: { base58: result.address },
|
|
51
|
+
privateKey: result.privateKey,
|
|
52
|
+
message: result.message,
|
|
53
|
+
};
|
|
49
54
|
}
|
|
50
55
|
catch (error) {
|
|
51
56
|
throw new Error(`Failed to generate account: ${error.message}`);
|
|
@@ -132,23 +137,16 @@ export async function getDelegatedResourceIndex(address, network = "mainnet") {
|
|
|
132
137
|
}
|
|
133
138
|
/**
|
|
134
139
|
* Activate a new account on the TRON network (costs bandwidth from the creator)
|
|
135
|
-
* @param privateKey Creator's private key
|
|
136
140
|
* @param newAddress Address to activate
|
|
137
141
|
* @param network Network name
|
|
138
142
|
* @returns Transaction hash
|
|
139
143
|
*/
|
|
140
|
-
export async function createAccount(
|
|
141
|
-
const tronWeb =
|
|
144
|
+
export async function createAccount(newAddress, network = "mainnet") {
|
|
145
|
+
const tronWeb = getTronWeb(network);
|
|
146
|
+
const ownerAddress = await getOwnerAddress();
|
|
142
147
|
try {
|
|
143
|
-
const transaction = await tronWeb.transactionBuilder.createAccount(newAddress,
|
|
144
|
-
|
|
145
|
-
const result = await tronWeb.trx.sendRawTransaction(signedTx);
|
|
146
|
-
if (result.result) {
|
|
147
|
-
return result.txid;
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
throw new Error(`CreateAccount failed: ${JSON.stringify(result)}`);
|
|
151
|
-
}
|
|
148
|
+
const transaction = await tronWeb.transactionBuilder.createAccount(newAddress, ownerAddress);
|
|
149
|
+
return await buildSignBroadcast(transaction, network);
|
|
152
150
|
}
|
|
153
151
|
catch (error) {
|
|
154
152
|
throw new Error(`Failed to create account: ${error.message}`);
|
|
@@ -156,23 +154,16 @@ export async function createAccount(privateKey, newAddress, network = "mainnet")
|
|
|
156
154
|
}
|
|
157
155
|
/**
|
|
158
156
|
* Update account name (can only be set once)
|
|
159
|
-
* @param privateKey Account's private key
|
|
160
157
|
* @param accountName New account name
|
|
161
158
|
* @param network Network name
|
|
162
159
|
* @returns Transaction hash
|
|
163
160
|
*/
|
|
164
|
-
export async function updateAccount(
|
|
165
|
-
const tronWeb =
|
|
161
|
+
export async function updateAccount(accountName, network = "mainnet") {
|
|
162
|
+
const tronWeb = getTronWeb(network);
|
|
163
|
+
const ownerAddress = await getOwnerAddress();
|
|
166
164
|
try {
|
|
167
|
-
const transaction = await tronWeb.transactionBuilder.updateAccount(accountName,
|
|
168
|
-
|
|
169
|
-
const result = await tronWeb.trx.sendRawTransaction(signedTx);
|
|
170
|
-
if (result.result) {
|
|
171
|
-
return result.txid;
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
throw new Error(`UpdateAccount failed: ${JSON.stringify(result)}`);
|
|
175
|
-
}
|
|
165
|
+
const transaction = await tronWeb.transactionBuilder.updateAccount(accountName, ownerAddress);
|
|
166
|
+
return await buildSignBroadcast(transaction, network);
|
|
176
167
|
}
|
|
177
168
|
catch (error) {
|
|
178
169
|
throw new Error(`Failed to update account: ${error.message}`);
|
|
@@ -180,25 +171,18 @@ export async function updateAccount(privateKey, accountName, network = "mainnet"
|
|
|
180
171
|
}
|
|
181
172
|
/**
|
|
182
173
|
* Update account permissions (multi-signature configuration)
|
|
183
|
-
* @param privateKey Account's private key
|
|
184
174
|
* @param ownerPermission Owner permission configuration
|
|
185
175
|
* @param activePermissions Active permission(s) configuration
|
|
186
176
|
* @param witnessPermission Optional witness permission (for Super Representatives)
|
|
187
177
|
* @param network Network name
|
|
188
178
|
* @returns Transaction hash
|
|
189
179
|
*/
|
|
190
|
-
export async function updateAccountPermissions(
|
|
191
|
-
const tronWeb =
|
|
180
|
+
export async function updateAccountPermissions(ownerPermission, activePermissions, witnessPermission, network = "mainnet") {
|
|
181
|
+
const tronWeb = getTronWeb(network);
|
|
182
|
+
const ownerAddress = await getOwnerAddress();
|
|
192
183
|
try {
|
|
193
|
-
const transaction = await tronWeb.transactionBuilder.updateAccountPermissions(
|
|
194
|
-
|
|
195
|
-
const result = await tronWeb.trx.sendRawTransaction(signedTx);
|
|
196
|
-
if (result.result) {
|
|
197
|
-
return result.txid;
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
throw new Error(`AccountPermissionUpdate failed: ${JSON.stringify(result)}`);
|
|
201
|
-
}
|
|
184
|
+
const transaction = await tronWeb.transactionBuilder.updateAccountPermissions(ownerAddress, ownerPermission, witnessPermission, activePermissions);
|
|
185
|
+
return await buildSignBroadcast(transaction, network);
|
|
202
186
|
}
|
|
203
187
|
catch (error) {
|
|
204
188
|
throw new Error(`Failed to update account permissions: ${error.message}`);
|