Comments (2)
Could you try to update to the latest version of hedera-local? I created a sample project and it works like a charm.
Sample
- index.js is like yours
const { Client, PrivateKey, AccountCreateTransaction, AccountBalanceQuery, Hbar, TopicCreateTransaction, AccountId, TopicMessageQuery, TopicMessageSubmitTransaction } = require("@hashgraph/sdk");
async function main() {
//Create your local client
const node = {"127.0.0.1:50211": new AccountId(3)};
const client = Client.forNetwork(node).setMirrorNetwork("127.0.0.1:5600"); //5600 //5551
client.setOperator(AccountId.fromString("0.0.2"),PrivateKey.fromString("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"));
//Create a new topic
let txResponse = await new TopicCreateTransaction().execute(client);
//Get the receipt of the transaction
let receipt = await txResponse.getReceipt(client);
//Grab the new topic ID from the receipt
let topicId = receipt.topicId;
//Log the topic ID
console.log(`Your topic ID is: ${topicId}`);
// Wait 5 seconds between consensus topic creation and subscription
await new Promise((resolve) => setTimeout(resolve, 5000));
new TopicMessageQuery()
.setTopicId(topicId)
.subscribe(client, null, (message) => {
let messageAsString = Buffer.from(message.contents, "utf8").toString();
console.log(`${message.consensusTimestamp.toDate()} Received: ${messageAsString}`);
});
}
main();
- msg.js
const {
Client,
PrivateKey,
AccountId,
TopicMessageSubmitTransaction
} = require("@hashgraph/sdk");
async function main() {
const node = {"127.0.0.1:50211": new AccountId(3)};
const client = Client.forNetwork(node).setMirrorNetwork("127.0.0.1:5600");
client.setOperator(AccountId.fromString("0.0.2"), PrivateKey.fromString("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"));
let sendResponse = await new TopicMessageSubmitTransaction({
topicId: '0.0.1054', // use the topic id from index.js
message: "Hello, HCS!",
}).execute(client);
const getReceipt = await sendResponse.getReceipt(client);
const transactionStatus = getReceipt.status;
console.log("The message transaction status " + transactionStatus);
}
main();
Usage
- run the index.js
ubuntu@ubuntu:~/sdk-topic-subscribe$ node index.js
Your topic ID is: 0.0.1054
- edit the topic id and run the msg.js
ubuntu@ubuntu:~/sdk-topic-subscribe$ node msg.js
The message transaction status 22
- back to the index.js terminal and the message should be logged
ubuntu@ubuntu:~/sdk-topic-subscribe$ node index.js
Your topic ID is: 0.0.1054
Thu Aug 25 2022 10:35:20 GMT+0300 (Eastern European Summer Time) Received: Hello, HCS!
from hedera-local-node.
Closing this due to inactivity.
@fed-franz Please feel free to reopen or file another issue in case of obstacles.
from hedera-local-node.
Related Issues (20)
- Smoke test when testing again relay node deployed by solo HOT 1
- Add a mechanism to override all of the relay's env variables without explicitly exposing them manually
- test: migration 0.48 to 0.49 HOT 1
- Remove deprecated `docker` definitions
- Improve error message when running with 'npm run restart' command HOT 1
- Add CLI flag for 'persistTransactionBytes'
- ci: Update conventional-pr-check source
- Beatify logger
- Updating dependencies breaks account creation HOT 1
- SDK actions workflow is failing at starting local node HOT 5
- Expose opcodes endpoint by default
- Fails in CI with PLATFORM_NOT_ACTIVE
- Update nick-fields/retry to use step-security maintained action
- Provide GitHub Action based on hedera-local-node
- Stopping the dockerized local node affects unrelated networks HOT 1
- ci: [2024-Q3] CI/CD Audit Story
- Local node doesn't work with mirror node version > `0.110.0-rc1`
- Set secret for codecov upload
- Local-Node not starting with tag command
- Intermittent failure on start of AccountCreationState
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hedera-local-node.