Hedera Consensus Service API

Verifiable timestamping and ordering of events for any application or permissioned blockchain framework.

Developer Quickstart

Consensus for any application

Enterprises and industry consortia building applications using industry-standard development environments or permissioned blockchain and distributed ledger frameworks, such as Hyperledger Fabric or R3 Corda, gain the benefits of privacy, low cost, and flexibility of development. But when used standalone, these applications and their associated networks remain siloed from one another, require complex and centralized configuration to achieve transaction ordering, and lack the fundamental element of public trust that is central to Web 3.0.

The Hedera Consensus Service (HCS) acts as a trust layer for any application or permissioned network and allows for the creation of an immutable and verifiable log of messages. Application messages are submitted to the Hedera network for consensus, given a trusted timestamp, and fairly ordered. Use HCS to track assets across a supply chain, create auditable logs of events in an advertising platform, or even use it as a decentralized ordering service.

Fast, fair, and secure consensus without compromise

Trust meets privacy
Combine the trust of Hedera’s public network with the privacy of a permissioned blockchain framework. Build applications that require privacy for sensitive data, public trust, and auditability.
Enterprise-grade network
Take advantage of Hedera’s high transaction throughout, fast finality, trusted timestamps, and security. Build decentralized applications never before possible.
Affordably low fees
A single HCS message costs $0.0001 USD, whether you’re using it standalone or in conjunction with a permissioned blockchain. You only pay for messages you submit.
Development flexibility
Build using any development language or the most ubiquitous permissioned blockchain frameworks. Set up your environment and submit your first message in no time.

A trusted real-time auditable log

Business and consumer applications today rely on expensive intermediaries to facilitate trust between parties for sharing data, transacting value, and meeting regulatory compliance.

Hedera Consensus Service (HCS) delivers decentralized trust for any new or existing application, across nearly every industry. Applications which benefit most from HCS require high-throughput, trusted timestamps and ordering, and fast finality. HCS also allows you to encrypt the content of sensitive messages for additional privacy.

“Advertisers can be more confident that their data is both accurate and tamper-proof, aiding in the fight to reduce ad-fraud and recover the billions of dollars lost each year in wasted ad spend.”

Ian Mullins
Founder and CEO

A decentralized ordering service for permissioned networks

Permissioned blockchain frameworks today, such as Hyperledger Fabric or R3’s Corda, rely on moderation, matching, and ordering performed by custom built and deployed consensus engines, such as Kafka or Raft. These services are prone to network outage, at risk of collusion by a small number of parties, and subject to the cost models of centralized infrastructure providers.

HCS combines the trust of Hedera’s public network, with the privacy of permissioned blockchain frameworks. It enables verifiable timestamps, decentralized ordering, and privacy for sensitive information, for enterprise applications and consortium.


"There’s tremendous value in combining the trustless consensus of a public network with the privacy of a permissioned network for all our sensitive transactions and data."

Liam Julien Lin
Co-founder and CEO

Interconnecting permissioned networks and consortia

Private consortia run a variety of applications across independent blockchain frameworks. Achieving interconnectivity between these frameworks today requires usage of centralized services with complex configurations and expensive overhead.

The Hedera public network acts as a trust layer for interconnecting application messages, running across independent blockchain frameworks. With verifiable timestamps and fair ordering of transactions, consortia can now share data, exchange value, and communicate with trust by sending transactions using HCS through the Hedera public network.


"There are a number of challenges in using traditional ordering services for decentralized applications. By exposing this capability, Hedera is making a meaningful contribution to furthering the capabilities of distributed networks."

Bryan Gross
Principal Product Manager

Step-by-step with Hedera Consensus Service

1: Create topic

A topic is created to manage the stream of messages for one application, such as a market where people bid on products.

2: Send

When an event happens – like a bid – it can be sent as an encrypted message to the topic.

3: Process

All of the messages are put into consensus order by the Hedera mainnet. A mirrornet can then send the messages for a particular topic to the application for processing.

4: Audit

When an audit needs to be conducted, previous messages can be checked, along with a state proof that ensures they have not been falsified.

Create a topic, send a message

Use the Hedera Consensus Service API to start building applications which take advantage of the high-throughput, fair ordering, and fast finality of Hedera Hashgraph.

Function

Create topic
  • Create topic
  • Submit Message
  • Subscribe to Mirror

const { ConsensusTopicCreateTransaction } = require("@hashgraph/sdk");


const transactionId = await  new ConsensusTopicCreateTransaction()

     .setMessage("Hello Hedera Consensus Service!")

     .setMaxTransactionFee( new Hbar(10)) 

     .execute(HederaClient);


const transactionReceipt = await transactionId.getReceipt(HederaClient);


console.log(transactionReceipt);

const { ConsensusSubmitMessage } = require("@hashgraph/sdk");


const transactionId = await  new ConsensusSubmitMessage()

     .setMessage("Hello decentralized messaging on Hedera Hashgraph!")

     .setMaxTransactionFee( new Hbar(1)) 

     .execute(HederaClient);


const transactionReceipt = await transactionId.getReceipt(HederaClient);


console.log(transactionReceipt);

const { MirrorConsensusTopicQuery } = require("@hashgraph/sdk");


new MirrorConensusTopicQuery()

    .setTopicId("0.0.123456789")

    .subscribe(MirrorNode, (message) => {

         console.log("Received message from our mirror node subscription:", message.toString());

         console.log("timestamp:", message.getTimestamp());

         console.log("runningHash:", message.getRunningHash());

         console.log("topicId:", message.getTopicId());

         console.log("sequenceNumber:", message.getSequenceNumber());

});

Consensus Service API features

Topic Management

Topics make it simple to organize transactions, so each application only receives the messages it needs.

Consensus Order

Messages are put into consensus order and given a timestamp by the Hedera network, with cryptographic proofs, so they are as trustworthy as the full Hedera network.

Audit log

Messages are cryptographically tied together with a running hash to provide an auditable, tamper-proof log of history.

Scalable transactions

Message processing and storage are kept outside the Hedera network. This allows higher speed and scalability.

Low Fees

The high speed and good scaling ensure low, micropayment fees on par with Hedera Cryptocurrency.

Historical Data

The Hedera Consensus Service ensures speed and security are kept on the ledger while storage is kept off-ledger. Choose to keep everything, nothing, or anything in between.

Explore Hedera Consensus Service

From ideation to building your application, check out these Hedera Consensus Service resources to help you along your journey.

A network for decentralized applications

Explore other Hedera network services to run powerful smart contracts and manage files.

Cryptocurrency

ENABLE FAST, LOW FEE PAYMENTS

Cryptocurrency payments allow you to transact without intermediaries to lower costs and make complex payments simple with code.
File Service

Sign and verify files

Create and manage files, with guaranteed visibility, acting as a revocation service for credentials. Hedera uniquely enables the ability to prove GDPR compliance with controlled mutability.
Smart Contract

TOKENIZE AND EXCHANGE ASSETS

The tokenized economy will change how we define ownership. Use the Solidity language to create assets, perform atomic swaps, or interact with outside oracles.

Ready to start building?

Get started with Hedera Consensus Service