-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-topic.js
More file actions
38 lines (28 loc) · 1.01 KB
/
Copy pathcreate-topic.js
File metadata and controls
38 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// create-topic.js
// run with node: node create-topic.js
const { Client, PrivateKey, TopicCreateTransaction } = require("@hashgraph/sdk");
const { exit } = require("process");
require("dotenv").config();
// Load your Hedera credentials
const operatorId = process.env.HEDERA_OPERATOR_ID;
const operatorKey = PrivateKey.fromString(process.env.HEDERA_OPERATOR_KEY);
// Create Hedera client
const client = Client.forTestnet().setOperator(operatorId, operatorKey);
async function main() {
try {
// Create a new topic
const tx = new TopicCreateTransaction().setSubmitKey(operatorKey);
const submitTx = await tx.execute(client);
// Get the receipt
const receipt = await submitTx.getReceipt(client);
// Extract Topic ID
const topicId = receipt.topicId.toString();
console.log("New topic created with ID:", topicId);
} catch (err) {
console.error("Error creating topic:", err);
}
// Close the client
client.close();
exit(0);
}
main();