dappily-agent-kit 0.1.0 → 0.3.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 +126 -121
- package/dist/actions/create_topic.d.ts +4 -0
- package/dist/actions/create_topic.d.ts.map +1 -0
- package/dist/actions/create_topic.js +136 -0
- package/dist/actions/create_topic.js.map +1 -0
- package/dist/actions/delete_topic.d.ts +4 -0
- package/dist/actions/delete_topic.d.ts.map +1 -0
- package/dist/actions/delete_topic.js +102 -0
- package/dist/actions/delete_topic.js.map +1 -0
- package/dist/actions/get_topic_info.d.ts +4 -0
- package/dist/actions/get_topic_info.d.ts.map +1 -0
- package/dist/actions/get_topic_info.js +79 -0
- package/dist/actions/get_topic_info.js.map +1 -0
- package/dist/actions/index.d.ts +5 -1
- package/dist/actions/index.d.ts.map +1 -1
- package/dist/actions/index.js +15 -1
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/submit_message.d.ts +4 -0
- package/dist/actions/submit_message.d.ts.map +1 -0
- package/dist/actions/submit_message.js +129 -0
- package/dist/actions/submit_message.js.map +1 -0
- package/dist/forge/actionSpec.d.ts +389 -0
- package/dist/forge/actionSpec.d.ts.map +1 -0
- package/dist/forge/actionSpec.js +127 -0
- package/dist/forge/actionSpec.js.map +1 -0
- package/dist/forge/generator.d.ts +9 -0
- package/dist/forge/generator.d.ts.map +1 -0
- package/dist/forge/generator.js +322 -0
- package/dist/forge/generator.js.map +1 -0
- package/dist/forge/index.d.ts +4 -0
- package/dist/forge/index.d.ts.map +1 -0
- package/dist/forge/index.js +12 -0
- package/dist/forge/index.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -1,24 +1,51 @@
|
|
|
1
1
|
# 🦞 Dappily Agent Kit
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**AI agent toolkit for Hedera — 15 actions + self-forging action generator.**
|
|
4
4
|
|
|
5
|
-
Give any AI agent the ability to interact with the Hedera network.
|
|
5
|
+
Give any AI agent the ability to interact with the Hedera network. Define actions as JSON specs, generate working TypeScript automatically.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## What's New in 0.3.0: The Forge
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
The kit now includes a **deterministic action generator**. Write a JSON spec → get a working, type-safe Hedera action with zero manual code.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
```typescript
|
|
12
|
+
import { validateSpec, generateAction } from "dappily-agent-kit";
|
|
13
|
+
import * as fs from "fs";
|
|
14
|
+
|
|
15
|
+
// Load a spec
|
|
16
|
+
const spec = JSON.parse(fs.readFileSync("my_action.spec.json", "utf-8"));
|
|
17
|
+
|
|
18
|
+
// Validate against the schema
|
|
19
|
+
const result = validateSpec(spec);
|
|
20
|
+
if (!result.ok) throw new Error(result.errors.join("\n"));
|
|
21
|
+
|
|
22
|
+
// Generate TypeScript code
|
|
23
|
+
const code = generateAction(result.spec);
|
|
24
|
+
fs.writeFileSync("src/actions/my_action.ts", code);
|
|
25
|
+
// → Compiles. Runs on testnet. Zero edits needed.
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Proven on testnet:** The generator produces actions that compile with `tsc --strict` and execute real transactions on Hedera testnet — token creation, HBAR transfers, consensus queries — all without a single manual fix.
|
|
29
|
+
|
|
30
|
+
## Testnet-Verified Actions
|
|
31
|
+
|
|
32
|
+
| # | Action | Domain | Testnet Proof |
|
|
33
|
+
|---|--------|--------|---------------|
|
|
34
|
+
| 1 | `GET_BALANCE` | Core | ✅ Live query |
|
|
35
|
+
| 2 | `HBAR_TRANSFER` | Core | ✅ Receipt: SUCCESS |
|
|
36
|
+
| 3 | `CREATE_TOKEN` | HTS Fungible | ✅ Token created |
|
|
37
|
+
| 4 | `ASSOCIATE_TOKEN` | HTS Fungible | ✅ |
|
|
38
|
+
| 5 | `TRANSFER_TOKEN` | HTS Fungible | ✅ |
|
|
39
|
+
| 6 | `MINT_TOKEN` | HTS Fungible | ✅ Supply verified |
|
|
40
|
+
| 7 | `BURN_TOKEN` | HTS Fungible | ✅ Supply verified |
|
|
41
|
+
| 8 | `CREATE_NFT_COLLECTION` | HTS NFT | ✅ Collection created |
|
|
42
|
+
| 9 | `MINT_NFT` | HTS NFT | ✅ Serials [1,2,3] |
|
|
43
|
+
| 10 | `TRANSFER_NFT` | HTS NFT | ✅ |
|
|
44
|
+
| 11 | `BURN_NFT` | HTS NFT | ✅ Serial destroyed |
|
|
45
|
+
| 12 | `CREATE_TOPIC` | HCS | ✅ Topic created |
|
|
46
|
+
| 13 | `SUBMIT_MESSAGE` | HCS | ✅ 3 messages, seq verified |
|
|
47
|
+
| 14 | `GET_TOPIC_INFO` | HCS | ✅ Memo + seq + keys |
|
|
48
|
+
| 15 | `DELETE_TOPIC` | HCS | ✅ Deleted + verified |
|
|
22
49
|
|
|
23
50
|
## Quickstart
|
|
24
51
|
|
|
@@ -29,159 +56,137 @@ npm install dappily-agent-kit @hashgraph/sdk
|
|
|
29
56
|
```typescript
|
|
30
57
|
import { HederaAgentKit, getBalanceAction, createTokenAction } from "dappily-agent-kit";
|
|
31
58
|
|
|
32
|
-
|
|
33
|
-
const agent = new HederaAgentKit(
|
|
34
|
-
"0.0.YOUR_ACCOUNT",
|
|
35
|
-
"YOUR_PRIVATE_KEY",
|
|
36
|
-
"testnet" // or "mainnet"
|
|
37
|
-
);
|
|
59
|
+
const agent = new HederaAgentKit("0.0.YOUR_ACCOUNT", "YOUR_KEY", "testnet");
|
|
38
60
|
|
|
39
61
|
// Check balance
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
42
|
-
console.log(balance.data.hbarBalance); // "150.5 ℏ"
|
|
43
|
-
}
|
|
62
|
+
const bal = await getBalanceAction.handler(agent, {});
|
|
63
|
+
if (bal.ok) console.log(bal.data.hbarBalance);
|
|
44
64
|
|
|
45
65
|
// Create a token
|
|
46
66
|
const token = await createTokenAction.handler(agent, {
|
|
47
|
-
name: "My Token",
|
|
48
|
-
symbol: "MTK",
|
|
49
|
-
initialSupply: 1000000,
|
|
50
|
-
decimals: 2,
|
|
67
|
+
name: "My Token", symbol: "MTK", initialSupply: 1000000, decimals: 2,
|
|
51
68
|
});
|
|
52
|
-
if (token.ok)
|
|
53
|
-
console.log(token.data.tokenId); // "0.0.XXXXX"
|
|
54
|
-
}
|
|
69
|
+
if (token.ok) console.log(token.data.tokenId);
|
|
55
70
|
```
|
|
56
71
|
|
|
57
|
-
##
|
|
72
|
+
## Standardized Output
|
|
58
73
|
|
|
59
|
-
|
|
74
|
+
Every action returns:
|
|
60
75
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
| `HBAR_TRANSFER` | `{ to, amount, memo? }` | Send HBAR to another account. |
|
|
76
|
+
```typescript
|
|
77
|
+
// Success
|
|
78
|
+
{ ok: true, summary: "...", txId: "...", receipt: { status: "SUCCESS" }, data: { ... } }
|
|
65
79
|
|
|
66
|
-
|
|
80
|
+
// Failure
|
|
81
|
+
{ ok: false, error: "INSUFFICIENT_PAYER_BALANCE", details: "..." }
|
|
82
|
+
```
|
|
67
83
|
|
|
68
|
-
|
|
69
|
-
|--------|-------|-------------|
|
|
70
|
-
| `CREATE_TOKEN` | `{ name, symbol, initialSupply, decimals?, memo? }` | Create a new fungible token. |
|
|
71
|
-
| `ASSOCIATE_TOKEN` | `{ tokenId, accountId?, accountPrivateKey? }` | Associate a token with an account. |
|
|
72
|
-
| `TRANSFER_TOKEN` | `{ tokenId, to, amount, memo? }` | Transfer fungible tokens. Pre-flight association check. |
|
|
73
|
-
| `MINT_TOKEN` | `{ tokenId, amount, supplyPrivateKey? }` | Mint additional supply. |
|
|
74
|
-
| `BURN_TOKEN` | `{ tokenId, amount, supplyPrivateKey? }` | Burn supply (irreversible). |
|
|
84
|
+
## The Forge: Self-Forging Actions
|
|
75
85
|
|
|
76
|
-
|
|
86
|
+
The Forge is a deterministic code generator that turns JSON specs into working Hedera actions.
|
|
77
87
|
|
|
78
|
-
|
|
79
|
-
|--------|-------|-------------|
|
|
80
|
-
| `CREATE_NFT_COLLECTION` | `{ name, symbol, maxSupply?, memo? }` | Create an NFT collection. |
|
|
81
|
-
| `MINT_NFT` | `{ tokenId, metadata: string[], supplyPrivateKey? }` | Mint NFTs with base64 metadata. Returns serial numbers. |
|
|
82
|
-
| `TRANSFER_NFT` | `{ tokenId, serial, to, senderPrivateKey? }` | Transfer an NFT. Pre-flight association check. |
|
|
83
|
-
| `BURN_NFT` | `{ tokenId, serial, supplyPrivateKey? }` | Burn an NFT (irreversible). |
|
|
88
|
+
### How It Works
|
|
84
89
|
|
|
85
|
-
|
|
90
|
+
1. **Spec** — A JSON file describing the action: inputs, SDK methods, transforms, error maps
|
|
91
|
+
2. **Validate** — Zod schema ensures the spec is machine-correct
|
|
92
|
+
3. **Generate** — Deterministic template fill produces TypeScript code
|
|
93
|
+
4. **Compile** — `tsc --strict` verifies type safety
|
|
94
|
+
5. **Test** — Run against Hedera testnet to verify real execution
|
|
86
95
|
|
|
87
|
-
|
|
96
|
+
### Spec Format (v4)
|
|
88
97
|
|
|
89
|
-
```
|
|
90
|
-
// Success
|
|
98
|
+
```json
|
|
91
99
|
{
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
"specVersion": 4,
|
|
101
|
+
"name": "MY_ACTION",
|
|
102
|
+
"category": "fungible",
|
|
103
|
+
"risk": "write",
|
|
104
|
+
"costTier": "medium",
|
|
105
|
+
"hedera": {
|
|
106
|
+
"sdkClass": "TokenCreateTransaction",
|
|
107
|
+
"sdkImports": ["TokenCreateTransaction", "Status"],
|
|
108
|
+
"networkCallType": "transaction"
|
|
109
|
+
},
|
|
110
|
+
"sdkMethods": [
|
|
111
|
+
{ "method": "setTokenName", "args": [{ "from": "input.name" }] }
|
|
112
|
+
],
|
|
113
|
+
"inputs": [
|
|
114
|
+
{ "name": "name", "type": "string", "required": true, "describe": "Token name" }
|
|
115
|
+
],
|
|
116
|
+
"successData": [...],
|
|
117
|
+
"errorMap": [...]
|
|
97
118
|
}
|
|
119
|
+
```
|
|
98
120
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
121
|
+
### CLI
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# Validate all specs
|
|
125
|
+
npm run forge:validate
|
|
126
|
+
|
|
127
|
+
# Generate an action from a spec
|
|
128
|
+
npm run forge:generate -- specs/create_token.spec.json output.ts
|
|
105
129
|
```
|
|
106
130
|
|
|
107
|
-
|
|
131
|
+
### 15 Reference Specs
|
|
132
|
+
|
|
133
|
+
The kit includes specs for all 15 built-in actions in `src/forge/specs/`. These serve as the pattern library — examples of every structural pattern:
|
|
134
|
+
|
|
135
|
+
- **Queries** (free, no signing): `get_balance`, `get_topic_info`
|
|
136
|
+
- **Simple transactions**: `create_token`, `create_topic`, `delete_topic`, `mint_token`, `burn_token`, `associate_token`, `mint_nft`, `burn_nft`, `submit_message`, `create_nft_collection`
|
|
137
|
+
- **Multi-arg transfers**: `hbar_transfer`, `transfer_token`, `transfer_nft`
|
|
108
138
|
|
|
109
139
|
## Action Discovery
|
|
110
140
|
|
|
111
141
|
```typescript
|
|
112
142
|
import { actions, getActionByName, findActionBySimile } from "dappily-agent-kit";
|
|
113
143
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
// Lookup by name
|
|
118
|
-
const action = getActionByName("HBAR_TRANSFER");
|
|
119
|
-
|
|
120
|
-
// Fuzzy match (for AI agents)
|
|
121
|
-
const match = findActionBySimile("send some hbar");
|
|
122
|
-
// → hbarTransferAction
|
|
144
|
+
actions.forEach(a => console.log(a.name));
|
|
145
|
+
getActionByName("HBAR_TRANSFER");
|
|
146
|
+
findActionBySimile("send some hbar"); // → hbarTransferAction
|
|
123
147
|
```
|
|
124
148
|
|
|
125
149
|
## Examples
|
|
126
150
|
|
|
127
|
-
See
|
|
151
|
+
See [`examples/`](./examples):
|
|
128
152
|
|
|
129
|
-
-
|
|
130
|
-
-
|
|
131
|
-
-
|
|
132
|
-
|
|
133
|
-
```bash
|
|
134
|
-
OPERATOR_ID=0.0.XXXXX OPERATOR_KEY=302e... npx ts-node examples/balance.ts
|
|
135
|
-
```
|
|
153
|
+
- `balance.ts` — Check account balance
|
|
154
|
+
- `fungible-lifecycle.ts` — Create → Mint → Transfer → Burn
|
|
155
|
+
- `nft-lifecycle.ts` — Create collection → Mint → Burn
|
|
156
|
+
- `hcs-lifecycle.ts` — Create topic → Submit messages → Query → Delete
|
|
136
157
|
|
|
137
158
|
## Security
|
|
138
159
|
|
|
139
|
-
⚠️
|
|
140
|
-
|
|
141
|
-
- Use environment variables or a vault for key storage
|
|
142
|
-
- Never log or persist private keys
|
|
143
|
-
- Plan to integrate wallet signing (HashPack / WalletConnect) for third-party accounts
|
|
144
|
-
- The `accountPrivateKey` and `supplyPrivateKey` fields will be replaced with a signing interface in a future version
|
|
160
|
+
⚠️ Private keys in action inputs are supported for **development/testing only**. For production, use environment variables or wallet signing.
|
|
145
161
|
|
|
146
162
|
## Architecture
|
|
147
163
|
|
|
148
164
|
```
|
|
149
165
|
dappily-agent-kit/
|
|
150
166
|
├── src/
|
|
151
|
-
│ ├── index.ts # Public API
|
|
152
|
-
│ ├── agent/
|
|
153
|
-
│ ├── actions/
|
|
154
|
-
│
|
|
155
|
-
│
|
|
156
|
-
│
|
|
157
|
-
│
|
|
158
|
-
│
|
|
159
|
-
│ │ ├── transfer_token.ts
|
|
160
|
-
│ │ ├── mint_token.ts
|
|
161
|
-
│ │ ├── burn_token.ts
|
|
162
|
-
│ │ ├── create_nft_collection.ts
|
|
163
|
-
│ │ ├── mint_nft.ts
|
|
164
|
-
│ │ ├── transfer_nft.ts
|
|
165
|
-
│ │ └── burn_nft.ts
|
|
166
|
-
│ └── types/action.ts # ActionResult, Action, etc.
|
|
167
|
+
│ ├── index.ts # Public API
|
|
168
|
+
│ ├── agent/ # HederaAgentKit
|
|
169
|
+
│ ├── actions/ # 15 built-in actions
|
|
170
|
+
│ ├── types/ # ActionResult types
|
|
171
|
+
│ └── forge/ # Self-Forging system
|
|
172
|
+
│ ├── actionSpec.ts # Spec schema (Zod, v4)
|
|
173
|
+
│ ├── generator.ts # Deterministic code generator
|
|
174
|
+
│ └── specs/ # 15 reference specs
|
|
167
175
|
├── examples/
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
│ └── nft-lifecycle.ts
|
|
171
|
-
├── dist/ # Built output (CJS + types)
|
|
172
|
-
├── package.json
|
|
173
|
-
├── tsconfig.build.json
|
|
174
|
-
└── LICENSE
|
|
176
|
+
├── dist/
|
|
177
|
+
└── package.json
|
|
175
178
|
```
|
|
176
179
|
|
|
177
180
|
## Roadmap
|
|
178
181
|
|
|
179
|
-
- [
|
|
180
|
-
- [
|
|
181
|
-
- [
|
|
182
|
-
- [ ]
|
|
183
|
-
- [ ]
|
|
184
|
-
- [ ]
|
|
182
|
+
- [x] 15 actions across HTS, NFT, HCS — all testnet-verified
|
|
183
|
+
- [x] Deterministic action generator (Forge)
|
|
184
|
+
- [x] 15 reference specs (v4 format)
|
|
185
|
+
- [ ] Sandbox runner (automated generate → compile → testnet)
|
|
186
|
+
- [ ] Prompt → Spec (LLM generates specs, generator does the rest)
|
|
187
|
+
- [ ] Mirror Node queries
|
|
188
|
+
- [ ] Framework adapters (Vercel AI, LangChain, MCP)
|
|
189
|
+
- [ ] Wallet signing interface
|
|
185
190
|
|
|
186
191
|
## License
|
|
187
192
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_topic.d.ts","sourceRoot":"","sources":["../../src/actions/create_topic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAgB,MAAM,iBAAiB,CAAC;AAOvD,QAAA,MAAM,iBAAiB,EAAE,MAgJxB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const zod_1 = require("zod");
|
|
4
|
+
const sdk_1 = require("@hashgraph/sdk");
|
|
5
|
+
const createTopicAction = {
|
|
6
|
+
name: "CREATE_TOPIC",
|
|
7
|
+
similes: [
|
|
8
|
+
"create topic",
|
|
9
|
+
"new topic",
|
|
10
|
+
"create channel",
|
|
11
|
+
"consensus topic",
|
|
12
|
+
"hcs topic",
|
|
13
|
+
"message topic",
|
|
14
|
+
],
|
|
15
|
+
description: "Create a new topic on the Hedera Consensus Service (HCS). Topics act as message streams — any account (or only authorized ones if a submit key is set) can publish messages. The operator key is used as admin key by default.",
|
|
16
|
+
examples: [
|
|
17
|
+
[
|
|
18
|
+
{
|
|
19
|
+
input: {
|
|
20
|
+
memo: "dappily-agent-kit event log",
|
|
21
|
+
},
|
|
22
|
+
output: {
|
|
23
|
+
ok: true,
|
|
24
|
+
summary: "Created topic 0.0.77777",
|
|
25
|
+
txId: "0.0.12345@1700000000.000000000",
|
|
26
|
+
receipt: { status: "SUCCESS" },
|
|
27
|
+
data: {
|
|
28
|
+
topicId: "0.0.77777",
|
|
29
|
+
memo: "dappily-agent-kit event log",
|
|
30
|
+
hasAdminKey: true,
|
|
31
|
+
hasSubmitKey: false,
|
|
32
|
+
explorerUrl: "https://hashscan.io/testnet/transaction/...",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
explanation: "Create an open topic (anyone can submit messages)",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
],
|
|
39
|
+
schema: zod_1.z.object({
|
|
40
|
+
memo: zod_1.z
|
|
41
|
+
.string()
|
|
42
|
+
.max(100)
|
|
43
|
+
.optional()
|
|
44
|
+
.describe("Short description of the topic's purpose"),
|
|
45
|
+
requireSubmitKey: zod_1.z
|
|
46
|
+
.boolean()
|
|
47
|
+
.optional()
|
|
48
|
+
.default(false)
|
|
49
|
+
.describe("If true, only the operator (or provided key) can submit messages. Default: open to all."),
|
|
50
|
+
adminPrivateKey: zod_1.z
|
|
51
|
+
.string()
|
|
52
|
+
.optional()
|
|
53
|
+
.describe("⚠️ Admin key (only if different from operator key)"),
|
|
54
|
+
submitPrivateKey: zod_1.z
|
|
55
|
+
.string()
|
|
56
|
+
.optional()
|
|
57
|
+
.describe("⚠️ Submit key (only if different from operator key). Only used if requireSubmitKey is true."),
|
|
58
|
+
}),
|
|
59
|
+
requiresConfirmation: false,
|
|
60
|
+
simulate: async (_agent, input) => {
|
|
61
|
+
return {
|
|
62
|
+
summary: `Create HCS topic${input.memo ? `: "${input.memo}"` : ""}${input.requireSubmitKey ? " (restricted submit)" : " (open submit)"}`,
|
|
63
|
+
estimatedFeeHbar: 0.01,
|
|
64
|
+
warnings: [],
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
handler: async (agent, input) => {
|
|
68
|
+
try {
|
|
69
|
+
const adminKey = input.adminPrivateKey
|
|
70
|
+
? sdk_1.PrivateKey.fromString(input.adminPrivateKey).publicKey
|
|
71
|
+
: agent.privateKey.publicKey;
|
|
72
|
+
const tx = new sdk_1.TopicCreateTransaction()
|
|
73
|
+
.setAdminKey(adminKey);
|
|
74
|
+
if (input.requireSubmitKey) {
|
|
75
|
+
const submitKey = input.submitPrivateKey
|
|
76
|
+
? sdk_1.PrivateKey.fromString(input.submitPrivateKey).publicKey
|
|
77
|
+
: agent.privateKey.publicKey;
|
|
78
|
+
tx.setSubmitKey(submitKey);
|
|
79
|
+
}
|
|
80
|
+
if (input.memo) {
|
|
81
|
+
tx.setTopicMemo(input.memo);
|
|
82
|
+
}
|
|
83
|
+
const frozenTx = await tx.freezeWith(agent.client);
|
|
84
|
+
if (input.adminPrivateKey) {
|
|
85
|
+
await frozenTx.sign(sdk_1.PrivateKey.fromString(input.adminPrivateKey));
|
|
86
|
+
}
|
|
87
|
+
const response = await frozenTx.execute(agent.client);
|
|
88
|
+
const receipt = await response.getReceipt(agent.client);
|
|
89
|
+
if (receipt.status !== sdk_1.Status.Success) {
|
|
90
|
+
return {
|
|
91
|
+
ok: false,
|
|
92
|
+
error: receipt.status.toString(),
|
|
93
|
+
details: `Topic creation failed with status: ${receipt.status.toString()}`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const topicId = receipt.topicId;
|
|
97
|
+
if (!topicId) {
|
|
98
|
+
return {
|
|
99
|
+
ok: false,
|
|
100
|
+
error: "NO_TOPIC_ID",
|
|
101
|
+
details: "Transaction succeeded but no topic ID was returned.",
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const txId = response.transactionId.toString();
|
|
105
|
+
return {
|
|
106
|
+
ok: true,
|
|
107
|
+
summary: `Created topic ${topicId.toString()}`,
|
|
108
|
+
txId,
|
|
109
|
+
receipt: { status: receipt.status.toString() },
|
|
110
|
+
data: {
|
|
111
|
+
topicId: topicId.toString(),
|
|
112
|
+
memo: input.memo || null,
|
|
113
|
+
hasAdminKey: true,
|
|
114
|
+
hasSubmitKey: !!input.requireSubmitKey,
|
|
115
|
+
explorerUrl: agent.getExplorerUrl(txId),
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
121
|
+
const knownErrors = {
|
|
122
|
+
INVALID_SIGNATURE: "Transaction signature is invalid. Check your keys.",
|
|
123
|
+
INSUFFICIENT_PAYER_BALANCE: "Not enough HBAR to cover the transaction fee.",
|
|
124
|
+
AUTORENEW_DURATION_NOT_IN_RANGE: "The auto-renew duration is outside the allowed range.",
|
|
125
|
+
};
|
|
126
|
+
const errorCode = Object.keys(knownErrors).find((code) => message.includes(code));
|
|
127
|
+
return {
|
|
128
|
+
ok: false,
|
|
129
|
+
error: errorCode || "CREATE_TOPIC_FAILED",
|
|
130
|
+
details: errorCode ? knownErrors[errorCode] : message,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
exports.default = createTopicAction;
|
|
136
|
+
//# sourceMappingURL=create_topic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_topic.js","sourceRoot":"","sources":["../../src/actions/create_topic.ts"],"names":[],"mappings":";;AAAA,6BAAwB;AAExB,wCAIwB;AAExB,MAAM,iBAAiB,GAAW;IAChC,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE;QACP,cAAc;QACd,WAAW;QACX,gBAAgB;QAChB,iBAAiB;QACjB,WAAW;QACX,eAAe;KAChB;IACD,WAAW,EACT,gOAAgO;IAClO,QAAQ,EAAE;QACR;YACE;gBACE,KAAK,EAAE;oBACL,IAAI,EAAE,6BAA6B;iBACpC;gBACD,MAAM,EAAE;oBACN,EAAE,EAAE,IAAI;oBACR,OAAO,EAAE,yBAAyB;oBAClC,IAAI,EAAE,gCAAgC;oBACtC,OAAO,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE;oBAC9B,IAAI,EAAE;wBACJ,OAAO,EAAE,WAAW;wBACpB,IAAI,EAAE,6BAA6B;wBACnC,WAAW,EAAE,IAAI;wBACjB,YAAY,EAAE,KAAK;wBACnB,WAAW,EAAE,6CAA6C;qBAC3D;iBACF;gBACD,WAAW,EAAE,mDAAmD;aACjE;SACF;KACF;IACD,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC;QACf,IAAI,EAAE,OAAC;aACJ,MAAM,EAAE;aACR,GAAG,CAAC,GAAG,CAAC;aACR,QAAQ,EAAE;aACV,QAAQ,CAAC,0CAA0C,CAAC;QACvD,gBAAgB,EAAE,OAAC;aAChB,OAAO,EAAE;aACT,QAAQ,EAAE;aACV,OAAO,CAAC,KAAK,CAAC;aACd,QAAQ,CAAC,yFAAyF,CAAC;QACtG,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2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const zod_1 = require("zod");
|
|
4
|
+
const sdk_1 = require("@hashgraph/sdk");
|
|
5
|
+
const deleteTopicAction = {
|
|
6
|
+
name: "DELETE_TOPIC",
|
|
7
|
+
similes: [
|
|
8
|
+
"delete topic",
|
|
9
|
+
"remove topic",
|
|
10
|
+
"close topic",
|
|
11
|
+
"destroy topic",
|
|
12
|
+
],
|
|
13
|
+
description: "Delete a Hedera Consensus Service (HCS) topic. Requires the admin key. This is irreversible — the topic will no longer accept messages and its data becomes inaccessible via the SDK.",
|
|
14
|
+
examples: [
|
|
15
|
+
[
|
|
16
|
+
{
|
|
17
|
+
input: {
|
|
18
|
+
topicId: "0.0.77777",
|
|
19
|
+
},
|
|
20
|
+
output: {
|
|
21
|
+
ok: true,
|
|
22
|
+
summary: "Deleted topic 0.0.77777",
|
|
23
|
+
txId: "0.0.12345@1700000000.000000000",
|
|
24
|
+
receipt: { status: "SUCCESS" },
|
|
25
|
+
data: {
|
|
26
|
+
topicId: "0.0.77777",
|
|
27
|
+
explorerUrl: "https://hashscan.io/testnet/transaction/...",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
explanation: "Delete a topic using the operator's admin key",
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
],
|
|
34
|
+
schema: zod_1.z.object({
|
|
35
|
+
topicId: zod_1.z
|
|
36
|
+
.string()
|
|
37
|
+
.regex(/^\d+\.\d+\.\d+$/, "Invalid Hedera Topic ID format (must be 0.0.X)")
|
|
38
|
+
.describe("The topic ID to delete"),
|
|
39
|
+
adminPrivateKey: zod_1.z
|
|
40
|
+
.string()
|
|
41
|
+
.optional()
|
|
42
|
+
.describe("⚠️ Admin key (only if different from operator key)"),
|
|
43
|
+
}),
|
|
44
|
+
requiresConfirmation: true,
|
|
45
|
+
simulate: async (_agent, input) => {
|
|
46
|
+
return {
|
|
47
|
+
summary: `Delete topic ${input.topicId}`,
|
|
48
|
+
estimatedFeeHbar: 0.005,
|
|
49
|
+
warnings: [
|
|
50
|
+
"⚠️ Topic deletion is irreversible. The topic will no longer accept messages.",
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
handler: async (agent, input) => {
|
|
55
|
+
try {
|
|
56
|
+
const tx = new sdk_1.TopicDeleteTransaction()
|
|
57
|
+
.setTopicId(input.topicId);
|
|
58
|
+
const frozenTx = await tx.freezeWith(agent.client);
|
|
59
|
+
if (input.adminPrivateKey) {
|
|
60
|
+
const adminKey = sdk_1.PrivateKey.fromString(input.adminPrivateKey);
|
|
61
|
+
await frozenTx.sign(adminKey);
|
|
62
|
+
}
|
|
63
|
+
const response = await frozenTx.execute(agent.client);
|
|
64
|
+
const receipt = await response.getReceipt(agent.client);
|
|
65
|
+
if (receipt.status !== sdk_1.Status.Success) {
|
|
66
|
+
return {
|
|
67
|
+
ok: false,
|
|
68
|
+
error: receipt.status.toString(),
|
|
69
|
+
details: `Topic deletion failed with status: ${receipt.status.toString()}`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const txId = response.transactionId.toString();
|
|
73
|
+
return {
|
|
74
|
+
ok: true,
|
|
75
|
+
summary: `Deleted topic ${input.topicId}`,
|
|
76
|
+
txId,
|
|
77
|
+
receipt: { status: receipt.status.toString() },
|
|
78
|
+
data: {
|
|
79
|
+
topicId: input.topicId,
|
|
80
|
+
explorerUrl: agent.getExplorerUrl(txId),
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
86
|
+
const knownErrors = {
|
|
87
|
+
INVALID_TOPIC_ID: "The topic ID does not exist on this network.",
|
|
88
|
+
UNAUTHORIZED: "The provided key is not the admin key for this topic.",
|
|
89
|
+
INVALID_SIGNATURE: "Transaction signature is invalid. Check the admin key.",
|
|
90
|
+
INSUFFICIENT_PAYER_BALANCE: "Not enough HBAR to cover the transaction fee.",
|
|
91
|
+
};
|
|
92
|
+
const errorCode = Object.keys(knownErrors).find((code) => message.includes(code));
|
|
93
|
+
return {
|
|
94
|
+
ok: false,
|
|
95
|
+
error: errorCode || "DELETE_TOPIC_FAILED",
|
|
96
|
+
details: errorCode ? knownErrors[errorCode] : message,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
exports.default = deleteTopicAction;
|
|
102
|
+
//# sourceMappingURL=delete_topic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete_topic.js","sourceRoot":"","sources":["../../src/actions/delete_topic.ts"],"names":[],"mappings":";;AAAA,6BAAwB;AAExB,wCAIwB;AAExB,MAAM,iBAAiB,GAAW;IAChC,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE;QACP,cAAc;QACd,cAAc;QACd,aAAa;QACb,eAAe;KAChB;IACD,WAAW,EACT,uLAAuL;IACzL,QAAQ,EAAE;QACR;YACE;gBACE,KAAK,EAAE;oBACL,OAAO,EAAE,WAAW;iBACrB;gBACD,MAAM,EAAE;oBACN,EAAE,EAAE,IAAI;oBACR,OAAO,EAAE,yBAAyB;oBAClC,IAAI,EAAE,gCAAgC;oBACtC,OAAO,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE;oBAC9B,IAAI,EAAE;wBACJ,OAAO,EAAE,WAAW;wBACpB,WAAW,EAAE,6CAA6C;qBAC3D;iBACF;gBACD,WAAW,EAAE,+CAA+C;aAC7D;SACF;KACF;IACD,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC;QACf,OAAO,EAAE,OAAC;aACP,MAAM,EAAE;aACR,KAAK,CAAC,iBAAiB,EAAE,gDAAgD,CAAC;aAC1E,QAAQ,CAAC,wBAAwB,CAAC;QACrC,eAAe,EAAE,OAAC;aACf,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,CAAC,oDAAoD,CAAC;KAClE,CAAC;IACF,oBAAoB,EAAE,IAAI;I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