This post was authored by Sreejith Kaimal and Ashu Mahajan, Application Architects at OpenCrowd. OpenCrowd is a design and technology firm that provides custom blockchain development and consulting services to enterprise clients and startups.
Coming to Hedera from a traditional blockchain background, one of the first things users must wrap their heads around is how the network handles state. As a development partner since 2017, we at OpenCrowd are keenly aware that companies building on Hedera need a seamless way to access all of their live and historical data in an operational data store. Additionally, users of these applications may want to access any relevant information about them. These issues are what led us to create the DragonGlass platform.
The DragonGlass API is a REST API that allows you to query historical data by transactions and accounts on both the testnet and mainnet.
For instance, if you’d like to query the balance of a given account at a certain point in time you can use the following:
https://api.dragonglass.me/hedera/api/accounts/{accountID}/balances/(asOfInEpoch}
As you can imagine this makes it easy to incorporate into your application. We’ll demonstrate how to in a few quick examples within a JavaScript environment.
If you’re trying to follow along you’ll need:
I’d also suggest using Postman to make it easy to format. After obtaining a DragonGlass access key, it’s straightforward to retrieve data from DragonGlass. We will start by first submitting a transaction to Hedera.
For the JS SDK, the sample client is available on the public repo at github.com/hashgraph/hedera-sdk-js. You could always build a custom client using the protobuf definitions for the Hedera APIs, but we’ll stick to JS SDK for this example.
import {Client} from "@hashgraph/sdk"; const client = new Client({ network: {"https://grpc-web.myhederawallet.com": "0.0.3"}, operator: { account: { shard: 0, real: 0, account: MyAccountID}, privateKey: MyPrivateKey }, });
import {Client} from "@hashgraph/sdk";
const client = new Client({ network: {"https://grpc-web.myhederawallet.com": "0.0.3"}, operator: { account: { shard: 0, real: 0, account: MyAccountID}, privateKey: MyPrivateKey },
});
Once you have set up your Hedera keys, the client can send a transaction. For the sake of our demo we'll do a simple cryptocurrency transfer:
new CryptoTransferTransaction() .addSender({ shard: 0, realm: 0, account: SenderAccount }, 10_000_000) .addRecipient({ shard: 0, realm: 0, account: ReceiverAccount }, 10_000_000) .build(client) .execute(client);
Now we can use the DragonGlass API to monitor this transaction by accountID. Notice you’ll need to add the DragonGlass API key to the GET request.
/** * Note: You should not expose your API key in browser. * i.e. Should not call DragonGlass directly from client app. * Ideally use your own server. Your client (UI) calls your server * which internally calls DragonGlass */ const apiKey = '<Your_Access_Key>'; const getTransactionsByAccount = (accountId) => fetch(`https://api.dragonglass.me/hedera/api/transactions?payerID=${accountId}`, { headers: { 'x-api-key': apiKey, Accept: 'application/json', Host: 'api.dragonglass.me' } });
/** * Note: You should not expose your API key in browser. * i.e. Should not call DragonGlass directly from client app. * Ideally use your own server. Your client (UI) calls your server * which internally calls DragonGlass */
const apiKey = '<Your_Access_Key>'; const getTransactionsByAccount = (accountId) => fetch(`https://api.dragonglass.me/hedera/api/transactions?payerID=${accountId}`, { headers: { 'x-api-key': apiKey, Accept: 'application/json', Host: 'api.dragonglass.me' } });
You can also use DragonGlass to fetch other types of Hedera transactions, such as contract calls, for a contractID in the transaction:
const getTransactionsByContract = (contractID) => fetch(`https://api.dragonglass.me/hedera/api/transactions? contractID=${contractID}&transactionType=CONTRACT_CALL`, { headers: { 'x-api-key': apiKey, Accept: 'application/json', Host: 'api.dragonglass.me' } });
const getTransactionsByContract = (contractID) =>
fetch(`https://api.dragonglass.me/hedera/api/transactions?
contractID=${contractID}&transactionType=CONTRACT_CALL`, {
headers: { 'x-api-key': apiKey, Accept: 'application/json', Host: 'api.dragonglass.me' }
Or fetch a raw transaction for a given DragonGlass generated transactionRecordID:
const getTransactionsByRecord = (transactionRecordID) => fetch(`https://api.dragonglass.me/hedera/api/transactions/raw? transactionRecordID=${transactionRecordID}`, { headers: { 'x-api-key': apiKey, Accept: 'application/json', Host: 'api.dragonglass.me' } });
const getTransactionsByRecord = (transactionRecordID) =>
fetch(`https://api.dragonglass.me/hedera/api/transactions/raw?
transactionRecordID=${transactionRecordID}`, {
It is of note that behind the scenes, and before the API even responds to your request, DragonGlass is automating many normally time-consuming services, such as signature verification and unmarshalling / indexing data. We think by doing so, we can help the community focus on building scalable decentralized applications without needing to invest precious time and money in building the platform that houses operational data.
The second major item of interest for dApp creators is the DragonGlass dApp Marketplace. Each dApp is given a dedicated page in the marketplace that provides detailed insight into dApp activities. Users can view transaction history, access smart contract templates and token transfer records, and quickly view stats such as the number of active users.
As the blockchain ecosystem becomes more and more decentralized, the need for a centralized information center becomes increasingly valuable; instead of dApp users having to navigate to multiple locations to reach relevant dApp information, they can simply visit DragonGlass and have all the info they need presented in a single, clean location.
With more and more users convening on DragonGlass each day, creating a dApp page is a simple and easy way to increase your product's visibility for potential new customers, connect with other dApp developers, and create a home base for your users.
A sample dApp page within the Marketplace
The Marketplace is currently live with pages for Tune.fm, Hash Name Service, AdsDax, PlayHash, and AoChain.
To recap, DragonGlass extends Hedera with a wide range of capabilities:
For the time being, we kept our focus on the two aspects of DragonGlass most relevant to dApp developers: the full set of DragonGlass APIs, and the dApp Marketplace. If you would like to feature your dApp on DragonGlass, or to learn more about the platform, please email [email protected] to get your dApp page set up and running.