Decentralized Data Queries: EthSign using subgraphs via The Graph for real-time blockchain indexing

Potter Li
Sign
Published in
4 min readJun 12, 2021

EthSign is a decentralized, versioned, and easily integrable signing dApp built on Web 3. We are officially announcing that EthSign is using subgraphs with The Graph for real-time data query. This article will provide an overview of The Graph and why EthSign uses The Graph. Find out how to use The Graph as a developer here.

About The Graph

The Graph is the indexing and query layer of the decentralized web. Developers build and publish open APIs, called subgraphs, that applications can query using GraphQL. The Graph currently supports indexing data from Ethereum, IPFS, and PoA with more networks coming soon. To date, over 11,000 subgraphs have been deployed by ~17,000 developers for applications, such as Uniswap, Synthetix, Aragon, Gnosis, Balancer, Livepeer, DAOstack, AAVE, Decentraland, and many others.

If you are a developer building an application or Web3 application, you can use subgraphs for indexing and querying data from blockchains. The Graph allows applications to efficiently and performantly present data in a UI and allows other developers to use your subgraph too! You can deploy a subgraph or query existing subgraphs that are in the Graph Explorer. The Graph would love to welcome you to be Indexers, Curators and/or Delegators on The Graph’s mainnet. Join The Graph community by introducing yourself in The Graph Discord for technical discussions, join The Graph’s Telegram chat, or follow The Graph on Twitter! The Graph’s developers and members of the community are always eager to chat with you, and The Graph ecosystem has a growing community of developers who support each other.

The Graph Foundation oversees The Graph Network. The Graph Foundation is overseen by the Technical Council. Edge & Node is one of the many organizations within The Graph ecosystem.

EthSign and The Graph Integration

In EthSign 2.0, we heavily relied on events to keep track of the state of our smart contract. Want to know what documents you have initiated? We need to query. Want to know what documents are shared with you? We need to query. This over-reliance on events was not a problem during local testing but proved to be fatal once deployed onto the public network. Our smart contract was painfully slow to load and the longer it had been deployed, the worse it had gotten.

Therefore, the solution is to either restructure the smart contract so retrieving the current state no longer relies on scanning past events or make use of a third-party indexing service. In the end, we adopted both approaches. While we restructured our smart contract to explicitly keep track of its current state as a backup, The Graph proved to be an excellent service and a perfect fit for our use case. Instead of reaching out to the blockchain network and waiting for up to 10 seconds for a response, we reach out to The Graph and get an instant response.

Aside from incredible indexing performance, The Graph’s powerful mapping system enables us to place custom triggers once certain events have been detected. Its GraphQL entity and query mechanisms also make retrieving data easy and efficient. The entire experience is so fluid that we decided to use The Graph to keep track of the current state of EthSign, including all contracts (essentially documents, not to be confused with the EthSign smart contract) for a specific user, the status of each contract, and the history of each contract.

For example, here is a contract being represented as a GraphQL entity in The Graph:

type Contract @entity {id: ID!initiator: User!name: Bytes!birth: BigInt!expiration: BigInt!doc_storage_id0: Bytesdoc_storage_id1: Bytesmeta_storage_id0: Bytesmeta_storage_id1: BytestotalSigners: Int!currentSigners: Int!currentSignedSigners: Int!currentSignedSignersList: [User!]!status: Int!events: [Event!]!}

And the following code that updates the current state of a particular contract is automatically executed by The Graph when a Solidity event of LogSignedDocument is emitted:

export function handleLogSignedDocument(event: LogSignedDocument): void {let ethsignEvent = new Event(event.transaction.hash.toHex() + "-" + event.logIndex.toString());ethsignEvent.type = "LogSignedDocument";ethsignEvent.blockNumber = event.block.number;ethsignEvent.timestamp = event.block.timestamp;ethsignEvent.contract = Contract.load(event.params.documentKey.toHexString()).id;ethsignEvent.involvedParty = event.params.signer;ethsignEvent.save();let ethsignContract = Contract.load(event.params.documentKey.toHexString());let events = ethsignContract.events;events.push(ethsignEvent.id);ethsignContract.events = events;++ethsignContract.currentSignedSigners;if (ethsignContract.currentSignedSigners == ethsignContract.totalSigners) {ethsignContract.status = 3;}let currentSignedSignersList = ethsignContract.currentSignedSignersList;currentSignedSignersList.push(event.params.signer.toHexString());ethsignContract.currentSignedSignersList = currentSignedSignersList;ethsignContract.save();}

As we can see, The Graph provides an incredibly familiar experience to developers who have worked with serverless cloud functions and acts as an L2 solution to blockchain metadata.

Consistent Vision

Some of the most tremendous features of EthSign eSignature platform are cross chain integrations, and a seamless multi-chain user experience. EthSign’s smart contract is deployed on Ethereum and many EVM-compatible blockchains. We are live on Avalanche, BSC, Polygon, Fantom, Moonbeam and so on and so is The Graph. The Graph has expanded to many blockchains and brings indexed open data to Ethereum, Polygon, Celo, Avalanche, BSC, Fantom and many others. And just like The Graph, EthSign will continue this cross chain vision as the future of Web 3.

Ultimately, The Graph serves as a catalyst to provide EthSign users a very user friendly experience.

Access EthSign here

More about The Graph

Your inputs are important to us, provide feedbacks here

[Twitter] [Discord] [Youtube] [LinkedIn]

--

--

Potter Li
Sign
Editor for

EthSign’s co-Founder | delivering notifications for EthSign