HumanKind: getting started with Hedera and DragonGlass
Jul 27, 2020
by The HumanKind Team
Human Kind Photo 1

What is HumanKind?

Geographically dispersed, and hunkered down in the middle of a pandemic, over 800 developers recently converged online to compete in the intense six-week virtual hackathon, Hedera20, focused on building the ultimate, decentralized app of the future.

Seeing the current disparity in the world and wanting to create something that would have a lasting social impact, our team spent the first week brainstorming over a dozen ideas, eventually consolidating and narrowing them down into a single project spanning the most promising aspects of each, called HumanKind:

HumanKind is a decentralized marketplace that aggregates, sponsors, and rewards altruistic behavior and random acts of kindness, giving back to the communities, businesses, and charities you care about. Essentially, the kinder you are, the more you - and the community you are a part of - get back.

Check out our pitch video.

It’s like Facebook marketplace meets Groupon but every aspect has a charitable component that gives back.

Simply Put: It Pays to Do Good Things

With the goal of aligning with Hedera’s mission of being “the trust layer of the internet,” and create a new “trust layer of social good,” we got to work. Knowing we couldn’t create every feature we’d thought of, we focused on the core:

  • Creating Your HumanKind Identity – Becoming “kind” isn’t as easy as it sounds 😊 Every HumanKind user is required to donate a small percentage of whatever they earn on the platform to their favorite causes and charities. We get them set up with all the traditional credentials, then ask them to create unique donation rules that will define where and how much they’d like to give back. Everyone also gets a kindness “score” that goes up based on how much they do on the platform.

  • Creating Marketplace Posts – We only focused on a single post type for the hackathon, but HumanKind users have lots of ways to earn and take action, including items for sale, help wanted, charitable posts (kind of like GoFundMe) and more. Businesses and charities can post to the platform as well, creating coupons and offers that give back.

  • Taking Action and Buying Things – You could decide you want to mow someone’s lawn, buy a pizza from Domino’s, or donate to a family in need. And even more ways to post are waiting in the wings.

  • Getting Rewarded – Regardless of what you decide to do, every time you do something kind on the platform, you earn money for your causes and charities and add to your kindness score. Imagine buying a Domino’s pizza, and they give 20% of the total price to your favorite charities! On the HumanKind platform it’s always a win-win.


Human Kind Photo 2

Getting Started

Wanting to take advantage of the trust, transparency and speed of Hedera Hashgraph, while also being conscious of off-ledger considerations, such as file storage and distributed identity and verifiable credential validation, our team took a hybrid architectural approach to building the solution, comprised of the following components:

  • React website – frontend
  • Node.js service – backend including interaction with Hedera Consensus Service
  • Java service – backend for Hedera distributed identity and verifiable credentials
  • Postgres database – database for off-ledger data storage and cache
  • Amazon S3 bucket – off-ledger file storage referenced by on-ledger Hedera Files
  • Amazon SQS – queue used for DragonGlass real-time subscription service

Human Kind Photo 3

Hedera Consensus Service

Hedera’s Consensus Service (HCS) is an incredibly easy-to-use, decentralized publish/subscribe API that allows application developers to add verifiable timestamping and ordering of events to their solution in a matter of minutes. We used it with the following goals in mind:

  • Fair Ordering – marketplace posts and activity should be fairly ordered by consensus of creation date/time

  • Proof of Action – proof should be created that users took action on marketplace posts, such as requesting to participate or marking work on a help wanted post as complete

  • Audit Logs – an auditable history of marketplace activity should be maintained, including a summary of donations that users could later reference for tax purposes

After reading the Getting Started with HCS and Javascript article, our hackathon team integrated these features by creating a topic and submitting messages each time data for an entity was created or updated, from our Node.js backend with just two generic methods and a few lines of code:

Code Snippet Background

// Create a Hedera Consensus Message to submit to our Hedera Consensus Topic

const submitHederaMessage = type => {

try {

const data = {

entity: this.tableName(), // the entity’s type, such as a “post” or “donation”

entityId: this.id, // the entity’s identifier

operation: type, // the operation type: “create” or “update”

data: this // the entity’s data

}

const message = new TextEncoder().encode(JSON.stringify(data))

submitMessage(message)

} catch (error) {

// log error

}

}

// Submit Hedera Consensus Message to our Hedera Consensus Topic

const submitMessage = async message => {

const transaction = await new ConsensusMessageSubmitTransaction()

.setTopicId(topicId)

.setMessage(message)

.build(HederaClient)

.sign(topicSubmitPrivateKey)

.execute(HederaClient)

const receipt = await transaction.getReceipt(HederaClient)

return receipt

}

DragonGlass real-time subscription service

Once we had messages getting submitted to our topic, we needed a way to get notified once the Hedera network gained consensus so we could update our local cache and fairly order marketplace posts and activity on the frontend. For this, we used a real-time subscription created through the DragonGlass portal, which automatically sets up an associated Amazon SQS queue filtered to specific topics to notify when consensus has been reached. In our Node.js backend, we added the sqs-consumer npm package, and setup a handler for updating the “consensusAt” timestamp for our entities. Again, after just a few lines of code, we were up and running:

Code Snippet Background

const { Consumer } = require('sqs-consumer')

const AWS = require('aws-sdk')

const handler = require('./handler')

AWS.config.update({

region: {awsRegion},

accessKeyId: {awsKey},

secretAccessKey: {awsSecret}

})

// since DragonGlass stores the message body data in hex, we need to convert

const convert = (from, to) => str => Buffer.from(str, from).toString(to)

const hexToUtf8 = convert('hex', 'utf8')

// setup Amazon SQS queue listener

const app = Consumer.create({

queueUrl: {sqsUrl},

handleMessage: async (message) => {

// received SQS message

if (message && message.Body) {

const messageBody = JSON.parse(message.Body)

if (messageBody && messageBody.data[0]) {

const messageBodyData = messageBody.data[0]

if (messageBodyData.message && messageBodyData.message.message) {

try {

// convert message to utf-8 encoding

const hcsMessageData = hexToUtf8(messageBodyData.message.message)

const data = JSON.parse(hcsMessageData)

handler.onData({

consensusAt: messageBodyData.consensusTime,

consensusSequence: messageBodyData.message.topicSequenceNumber,

data

})

} catch (e) {

// log error

}

}

}

}

},

sqs: new AWS.SQS({ apiVersion: '2012-11-05' })

})

app.on('error', (err) => {

handler.onError(err.message)

})

app.on('processing_error', (err) => {

handler.onError(err.message)

})

app.on('timeout_error', (err) => {

handler.onError(err.message)

})

// start listening

app.start()


// handler.js

const onData = ({ consensusAt, consensusSequence, data }) => {

try {

const entity = data.entity

const entityId = data.entityId

// update local database table {entity} where id = {entityId}

} catch (error) {

// log error

}

}

What’s next?

By leveraging the resources available from Hedera and DragonGlass, HumanKind went from having no prior experience with Hedera Hashgraph, to building a robust, award-winning decentralized marketplace in a few short weeks. To lead by example, we’ve donated a percentage of all prize winnings to our favorite charities, including the John W. Brick Foundation for mental health and Heart-to-Heart International, which is providing worldwide COVID-19 relief to first responders.

We hope HumanKind becomes the first step toward making kindness a habit instead of an afterthought. Since the hackathon ended, we’ve been identifying key partners that believe in our vision of giving back and who would like to collaborate around our roadmap as we work towards go-live in the next few months.

If you or someone you know are part of a socially conscious business or charitable organization that might be interested in participating, please reach out directly at [email protected] or visit https://humankind.ly to learn more.

Human Kind Photo 4