Skip to main content

gRPC Quick Start

info

You will need:

  • Arkhia gRPC Service URL

The gRPC can be retrieved from the Arkhia Dashboard after you Create a Project.

Don't have an account yet with Arkhia? Signup.

Subscribe to a Topic

    const {         Client,        TopicMessageQuery     } = require("@hashgraph/sdk");    const nodes = { "35.237.100.180:50211" : "0.0.3"}    const topicId = `<YOUR_TOPIC_ID>`; // https://explorer.arkhia.io/#/testnet/topics    const accountId = `<YOUR_HEDERA_ACCOUNT_ID>`;    const privateKey = `<YOUR_HEDERA_PRIVATE_KEY>`;    const arkhiaGRPC = '<ARKHIA_GRPC_URL>';    async function createClient() {        if (accountId == null || privateKey == null ) {            throw new Error("Variables accountId and privateKey must be present");        }        const client = Client.forNetwork(nodes).setMirrorNetwork(arkhiaGRPC);        client.setOperator(accountId, privateKey);        return client;    }    async function getMessagesFromTopic(topicId) {        const client = await createClient();        console.log(`Subscribing to ${arkhiaGRPC}`);        //Create the query        new TopicMessageQuery()            .setTopicId(topicId)            .setStartTime(0)            .subscribe(                client,                (message) => console.log(topicId + ": -> " + Buffer.from(message.contents, "utf8").toString())            );    }    getMessagesFromTopic(topicId);