Decentralized Application Metrics and Analysis

When building a dApp it can be daunting to track all of the activity that occurs on the blockchain. We want to simplify that! We'll be discussing the ways in which we can monitor your dApp's infrastructure and provide better anayltics and useablility. In order to meet demands of your users it crucial that you understand what exactly is happening with your dApp. Although highly dependant upon your specific dApp's needs there are a few core peices most dApp will need:

  • Real-time Usage Monitoring
  • Historical or time-series data for analyzing user adoption and growth
  • Token Metrics: Transfers, Holders, and Market data

Amberdata provides an simple way to access all of this data.

Real-time monitoring of user interactions

In order to get real-time update of user interactions, you can utilize our websockets to get a notification for all new activity. This is especially important for dApp developers as you'll need to update your applications and respond to value transfers, signals and activity when they occur. You can then integrate this into a front-end UI which will provide a fluid user experience.

const Web3Data = require("web3data-js")

// Create the Web3Data instances passing in  your API Key (Get one! -> amberdata.io/onboarding)
const w3d = new Web3Data(process.env.API_KEY)

/* Helpers */

// Get the human readable text signature of the event
const getTextSig = async (hashSig) => w3d.signature.getSignature(hashSig).then( data => data.length > 0 ? data[0].textSignature : '')

// Init websocket connection
w3d.connect()

// Watch for contract events i.e. transfers, pregnant kitties ect.
w3d.on({eventName:'address:logs', filters: {"address": cryptoKittiesContract} },
    async data => {

        const hashSig = data.topics[0].slice(0, 10)
        const textSignature = await getTextSig(hashSig)

        // Construct a nice logging message to signal a new event
        const eventMessage =
        `event ${textSignature} at ${new Date(data.timestamp).toLocaleString()} in block ${data.blockNumber}`
        // Log to console
        console.log(textSignature !== '' ? eventMessage : `sig ${textSignature} not found`)
})

// Watch for all new transactions
w3d.on({eventName:'address:transactions', filters: {"address": cryptoKittiesContract} },
    async data => {
        console.log(`New transaction ${data.hash.slice(0,10)} at ${data.timestamp}`)
})

// Watch for all new pending transactions
w3d.on({eventName:'address:pending_transactions', filters: {"address": cryptoKittiesContract} },(pending_txns) => {

Try out the example on runkit!

Historical or time-series data for analyzing user adoption and growth

It's important to understand how users are using your dApp and it's rate of adoption. This will provide actionable data and determine the future of your application. We provide several ways to do this. One way is to get historical data detailing the number of users interacting with your dApp. You can then create time-series graphs and analyze user adoption, determine rate.

const Web3Data = require("web3data-js")

// Create the Web3Data instances passing in  your API Key (Get one! -> amberdata.io/onboarding)
// If you're signed in and have an api key it will get autopopulated here!
const w3d = new Web3Data(process.env.API_KEY)

// Need profressional key to work
const profKeyError = e => console.log('Need Professional API Key')

// We'll get the adoption and usage statistics of our address which will give us an idea of
// how our user base is doing
const getGrowthMetrics = async (address) => {
    const config = { timeFrame: '30d', timeFormat: 'iso' }
    const [adoption, usage] = await Promise.all(
        [w3d.address.getAdoption(address, config).catch(profKeyError), w3d.address.getUsage(address, config).catch(profKeyError)])
    return {adoption, usage}
}

// We're using cryptokitties as an example but this would be the main contract address of dApp you are monitoring
const cryptoKittiesContract = "0x06012c8cf97bead5deae23707

Try out the example on runkit!

Token Metrics: Transfers, and Holders

If you're managing a dApp that has tokens it's important to have knowledge of the usage of your token, as well as, it's value if it is a traded token. It's possible to a get a current and historical view of every address that is holding your token. This data will help you make better more informed development and business decisions about your dApp. Using historical transfer data, you can build reports of how tokens holders are using the token. For instance, average length of time that an address holds a token. Information like this could prove valuable to dApp users and stakeholders.

const Web3Data = require("web3data-js")

// Create the Web3Data instances passing in  your API Key (Get one! -> amberdata.io/onboarding)
const w3d = new Web3Data(process.env.API_KEY)

// Need profressional key to work
const profKeyError = e => console.log('Need Professional API Key')

// Contract we'll use as an example but you would but the address of your dApp here
const BAT_CONTRACT = '0x0d8775f648430679a709e98d2b0cb6250d2887ef'

// Get the latest token holders
const tokenHolders = w3d.token.getHolders(BAT_CONTRACT).catch(profKeyError)

// Get historical token transfers + price for analysis
const tokenTransfers = w3d.token.getTransfers(BAT_CONTRACT).catch(profKeyError)

// Watch for new token transfers
w3d.connect()
w3d.on({eventName: 'token_transfers', filters: {address: BAT_CONTRACT}}, transfer => {
    const amount = transfer.amount / Math.pow(10, 18)
    const time = (new Date(transfer.timestamp)).toLocaleString()
    console.log(`${amount} BAT transfered at ${time}` )
})

Try out the example on runkit!

Token Metrics: Market data

For traded tokens, we offer numerous ways to get pricing and trade data associated with your token. Use this data internally to build alerting and monitoring solutions to stay informed about the market health of your token. Externally, you can provide this information to your community and token holders. This will give them a better sense of your dApp's market health.

const Web3Data = require("web3data-js")

// Create the Web3Data instances passing in  your API Key (Get one! -> amberdata.io/onboarding)
// If you're signed in and have an api key it will get autopopulated here!
const w3d = new Web3Data(process.env.API_KEY)

// Contract we'll use as an example but you would but the address of your dApp here
const BAT_CONTRACT = '0x0d8775f648430679a709e98d2b0cb6250d2887ef'

// Get time from 1 day ago
let startDate = new Date()
startDate.setDate(startDate.getDate() - 1)
startDate = startDate.getTime()

// Get current price data for token contract
const currentPriceData = await w3d.market.getTokenPrices(BAT_CONTRACT)
console.log({currentPriceData})

// We can adjust the window using the 'startDate' & 'endDate' parameters
// for now we want historical prices over last 24 hours
const histPriceData = await w3d.market.getTokenPrices(BAT_CONTRACT, {startDate})
console.log({histPriceData})

// Watch for token price changes
w3d.connect()
w3d.on({eventName: 'market:prices', filters: { "pair": "bat_usd"}}, price => {
    const time = (new Date(price.timestamp)).toLocaleString()
    console.log(`Token price update ${price.price} at ${time}`)
})

// Watch for tokens being traded on an exchange
w3d.on({eventName: 'market:trades', filters: { "pair": "bat_usd"}}, ([trade]) => {
    const time = (new Date(trade[2])).toLocaleString() // Human readable timestamp
    const price = trade[5]
    const volume = trade[6]
    const type = trade[7] ? 'bought' : 'sold'

    console.log(`${volume} BAT ${type} for ${price} at ${time}`)
})

Try out the example on runkit!