Defining smart contract activity metrics

Dmytro
Chainbeat
Published in
8 min readJul 17, 2019

You can’t control what you can’t measure.
Tom DeMarco

A growing business needs to be closely measured and carefully managed to ensure its success. Putting performance measurement systems in place is an important way of keeping track of the progress and provides the starting point for a system of target-setting that will help implement growth strategies for the business.

In the early days of the internet, information was very disorganized. Until search engines like Google came long indexing information and turning the web into more usable and understandable. Along with the search engines, came a plethora of tools for Internet-based businesses that allowed them to track and measure all customer activities across their web, desktop or mobile apps. All these analytics tools helped the Internet-based businesses understand customer behavior better and helped them to easily adapt to satisfy customer needs. Eventually turning these businesses into market leaders overthrowing traditional brick and mortar competition.

Now we have a shifting paradigm in technology, where blockchain technology is fueling the growth of a new type of decentralized ecosystem. Decentralized Applications(or DApps) are turning out to be the next generation of applications for a boundaryless world. We are in the early stages of innovation and can compare the current environment to what the internet was 15 years ago.

There are a few block explorer initiatives that have started to help developers and businesses understand the usage in their DApps. But most of them are in the early stages. In fact, there are a few hacky ways by which we could attain tracking like collecting data in the UI layer or comparing activities in smart contracts between two periods of time. But with so many interactions in smart contracts, it’s hard to make sense of the data.

At Chainbeat our initial focus has been on DApps running on Ethereum. The first step in data analytics is to define the metrics. To define metrics for DApps running on an EVM, it’s important to understand how smart contracts work and what we can measure in the system.

A quick introduction into Ethereum blockchain

You can skip this paragraph if you understand how it works.

Ethereum blockchain consists of linked blocks and every next block points to the previous. Every block contains transactions and every transaction is an interaction between two addresses in the network. Every transaction can change the state (of the smart contract) and emit events (logs). Also, every block has a timestamp and this is important for us because we are looking for insights and how smart contract activity changes over time.

A simplified representation of the Ethereum blockchain

ERC20 token standard

One of the most used types of smart contracts is ERC20 tokens. Basically, it’s your own cryptocurrency inside Ethereum blockchain. Tokens can represent shares in a company, another cryptocurrency (see WBTC) or real currency (like USDC), airline miles and basically… anything. We’ll use such contract as an example in this article.

Metric #1 — Transactions per day

Why do we create smart contracts? To execute transactions, of course! In the case of an ERC20 token, there are several transactions like Transfer, TransferFrom, and Approve. The simplest way to get started is to monitor how the transactions change over time. For example, the number of transactions can go up if a token was listed in a new exchange or if the project has been mentioned in the news.

Example report — USDC transactions

Metric #2 — Events per day

Events are inheritable members of contracts. When they are called, they cause the arguments to be stored in the transaction’s log — a special data structure in the blockchain. We can build a report by scanning event logs for a smart contract and display the number of events a day and add a filtering option by event type.

Smart contract developers use events as a way to track significant functionality execution. Most popular events related to tokens are Transfer, Approval, Mint, Burn. It’s common to have an event name similar to the method name, but we should not confuse method calls ( transactions ) and events because they are different. Complex transactions can emit several events (log records).

A transaction can emit several events or emit none. For example, a transaction performing an airdrop to an array of addresses can emit hundreds of transfer events.

Some events signal important changes to a smart contract, such as OwnershipChanged or adminWithdrawal. It’s possible to use Chainbeat to keep an eye on events of interest and get a notification when an event occurs. For example, a manager may want to receive a notification every time adminWithdrawal event occurs to prevent any misuse or notice unauthorized calls (example: an admin private key getting compromised).

Example report — Basic Attention Token events

Metric #3 — Daily active users

This is my favorite metric. Every user in the blockchain is represented by address (which is defined by private/public key). We can count the number of unique addresses performing transactions and refer them as “active users”. Active Users can be an actual user or a smart contract performing a transaction. And we can call it “active users”. Because most of the time, one regular user will use one address to interact with a contract. Daily active users is an important metric that can signal the life cycle stage of the DApp. During the early stages of development, the developers and early adopters are the most active users creating a significant number of transactions. As the DApp matures, the usage begins to spread and the active user count rises.

Sidechains are getting more and more popular and ideally, active users of a system should be calculated on mainnet and project sidechain for accuracy. Adding Sidechain support to Chainbeat is in our roadmap.

Example report — Wrapped Ether active users

Metric #4 — Gas used

Before we talked about pretty intuitive metrics. This one is more technical and focused on developers. Every transaction consumes “gas” — a measure of computing and storage usage. Every block is limited by the amount of gas can be used (about 8 000 000 at this moment). The more gas a transaction consumes the bigger is the fee. This is a smart way to keep users from putting “bad data” in blockchain.

With the gas used report, we can observe key smart contract traits such as size, complexity and potential issues within the smart contracts. Hypothetically if the transaction consumed 8 000 000 of gas, it consumed an entire block. What if we calculate the amount of gas used by a smart contract a day, per method?

This metric shows how smart contract uses blockchain resources. Smaller gas consumption per transaction is better. I find this one very useful for smart contract developers because optimizing how resources are used is the key to a successful DApp.

Example report — CryptoKitties gas report

Metric #5 — ERC-20 (ERC-721) token volume

While metrics 1–4 can be applied to any smart contract. This one is specific for tokens. Because token transfers can be measured, we can count the total amount of tokens transferred per day and build a chart (or table) with this information. It will show us the amount of funds ( or a number of crypto-kitties ) being transferred a day and we will be able to see how this value changes in time.

Example report — USDC Volume

Metric #6 — Token Holders

Very similar to active users, but more static. By looking at the report you can quickly get insights such as:

  • What is the total amount of users holding ERC20/ERC721 tokens?
  • How token balances are distributed?
  • In a few cases, it’s entirely possible that some smart contract has 99% of tokens in one wallet, while in others the distribution is fairly even.
Example report — Tether token holders

Metric #7 — Balance (Ether or ERC20)

Some smart contracts accumulate some tokens (or more often ETH). This can be a notorious ICO, DAO or a Uniswap contract. For example, if a smart contract powers ICO — it’s Ether balance shows how much money was raised.

If we look at MolochDAO, guild bank’s balance in WETH (wrapped ether) grows as a project attracts new members. Balance is a very good metric for financial projects.

Example report — MolochDAO guild bank balance report

Another key usage of this report is to act as a monitor for any type of wallets. You can read more about our support for wallets here.

Summary

There is so much more that you can do with Chainbeat. The goal of this post was to explain the core reporting features of Chainbeat. In future posts we will be delving into in-depth details of some of the other features.

Scanning the blockchain is a complicated process and requires running a full synchronized node, having a database and background workers. While some blockchain companies try to build their own analytics solutions, our goal is to build a simple and user-friendly way to calculate these metrics for smart contracts and provide easy access to this type of data on demand.

We created Chainbeat.io to provide blockchain analytics as a service to everyone.

This way companies and individuals can focus on what they do best — building their projects!

PS:

Pssst… don’t tell anyone, but you don’t need to be a creator or owner of a smart contract to use Chainbeat. Since all data is in public blockchain it’s possible to explore the activity of any smart contract out there.

--

--