Skip to content
Blocktivity EOSIO Stats
Shell TypeScript C++ JavaScript
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
contracts/blocktivity fix cpu_usage_ms & net_usage_words Nov 4, 2019
examples add shell examples Nov 6, 2019
scripts add timestamp to periods Nov 4, 2019
src Fetch data directly from `execution_trace` instead of `action_trace` Nov 9, 2019
.env.example update configs Nov 7, 2019
.gitignore finish contract Nov 1, 2019
LICENSE Initial commit Oct 29, 2019
README.md add chains to README Nov 7, 2019
ecosystem.config.js update deploy Nov 7, 2019
eosc-vault.json push clean Nov 2, 2019
history.ts remove 1 block from history Nov 7, 2019
index.ts add history in main Nov 7, 2019
package.json
tsconfig.json push prototype Oct 30, 2019

README.md

Blocktivity EOSIO Stats

EOS Nation has built an open-source solution for Blocktivity statistics

Which includes:

  1. Server-Side: Calculate action & transaction counts
  2. Smart Contract: Hourly/Daily/Weekly statistics

We plan on deploying this solution/smart contracts on every EOSIO compatible blockchains to allow for more transparent statistics.

Chains

History solution (required)

Examples - NodeJS/Javascript

install

$ npm install node-fetch eosjs

sum.js

const fetch = require("node-fetch");
const { JsonRpc } = require("eosjs");

const rpc = new JsonRpc("https://eos.eosn.io", { fetch });

const code = "blocktivity1";
const scope = "blocktivity1";
const table = "sum";

rpc.get_table_rows({ json: true, code, scope, table }).then((data => {
  console.log(data.rows[0]);
  // { hour: 815997,
  // day: 20310523,
  // week: 128191484,
  // last_updated: '2019-11-06T15:48:24' }
}))

periods.js

const fetch = require("node-fetch");
const { JsonRpc } = require("eosjs");

const rpc = new JsonRpc("https://eos.eosn.io", { fetch });

const code = "blocktivity1";
const scope = "blocktivity1";
const table = "periods";
const limit = 168

rpc.get_table_rows({ json: true, code, scope, table, limit }).then((data => {

  for (const row of data.rows) {
    console.log(row);
    // { block_num: 88228800,
    //   timestamp: '2019-11-05T02:35:49',
    //   transactions: 178877,
    //   actions: 826073,
    //   cpu_usage_us: 316587911,
    //   net_usage_words: 8364304 }
  }
}))

Examples - cURL

Request sum statistics

curl --request POST \
  --url http://eos.eosn.io/v1/chain/get_table_rows \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{"code":"blocktivity1","table":"sum","scope":"blocktivity1","json":true}' | jq .

JSON response

{
  "rows": [
    {
      "hour": 875365,
      "day": 20773084,
      "week": 83237200,
      "timestamp": "2019-11-03T16:48:21"
    }
  ],
  "more": false
}

Request periods (hourly intervals of 7200 blocks)

curl --request POST \
  --url http://eos.eosn.io/v1/chain/get_table_rows \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{"code":"blocktivity1","table":"periods","scope":"blocktivity1","json":true,"limit":168}' | jq .

JSON response

{
  "rows": [
    {
      "block_num": 87696000,
      "timestamp": "2019-11-03T16:48:21",
      "transactions": 379379,
      "actions": 1211942,
      "cpu_usage_us": 63476,
      "net_usage_words": 1772
    }
    ...
  ],
  "more": true
}

1. Server-Side

Install

$ git clone https://github.com/EOS-Nation/blocktivity-eos-stats.git
$ cd blocktivity-eos-stats
$ npm install

Config

.env

# Standard Nodeos
NODEOS_ENDPOINT="http://eos.eosn.io"

# (Required) History Solution
HISTORY_TYPE="dfuse"
NETWORK="mainnet"
NODEOS_ENDPOINT_HISTORY="http://eos.greymass.com"

# (Optional) Push results to on-chain contract
NODEOS_ENDPOINT_CONTRACT="http://localhost:8888"
ACTOR="blocktivity1"
PERMISSION="push"

# (Private) keys & tokens
DFUSE_TOKEN="<PRIVATE DFUSE TOKEN>"
PRIVATE_KEY="<PRIVATE KEY>"

# (Optional) server-side settings
ONE_HOUR=7200
PAUSE_MS=60000
CONCURRENCY=3

Quick Start

$ npm start

2. Smart Contract

ACTION

TABLE

ACTION push

Pushes hourly (7200 blocks) statistics of transaction & action counts.

  • Authority: get_self()

params

  • {uint64_t} block_num - block number start (rounded to the nearest 7200 interval)
  • {time_point_sec} timestamp - block creation timestamp (UTC)
  • {uint64_t} transactions - number of actions during 1 hour period
  • {uint64_t} actions - number of transactions during 1 hour period

example

cleos push action blocktivity push '[87458400, "2019-11-03T16:48:21", 299282, 281802]' -p blocktivity

TABLE periods

  • {uint64_t} block_num - start of block number
  • {time_point_sec} timestamp - block creation timestamp (UTC)
  • {uint64_t} transactions - number of actions during 1 hour period
  • {uint64_t} actions - number of transactions during 1 hour period
  • {uint64_t} cpu_usage_us - number of cpu_usage_us during 1 hour period
  • {uint64_t} net_usage_words - number of net_usage_words during 1 hour period

example

{
  "block_num": 87458400,
  "timestamp": "2019-11-03T16:48:21",
  "transactions": 299282,
  "actions": 281802,
  "cpu_usage_us": 63476,
  "net_usage_words": 1772
}

TABLE sum

  • {uint64_t} hour - hourly number of actions
  • {uint64_t} day - daily number of actions
  • {uint64_t} week - weekly number of actions
  • {time_point_sec} last_updated - last updated (UTC)

example

{
  "hour": 875365,
  "day": 20773084,
  "week": 83237200,
  "last_updated": "2019-11-03T16:48:21"
}

TABLE average

  • {uint64_t} hour - average hourly number of actions (7 day average)
  • {uint64_t} day - average daily number of actions (7 day average)
  • {uint64_t} week - weekly number of actions
  • {time_point_sec} last_updated - last updated (UTC)

example

{
  "hour": 875365,
  "day": 20773084,
  "week": 83237200,
  "last_updated": "2019-11-03T16:48:21"
}

TABLE record

  • {uint64_t} hour - highest hourly number of actions
  • {uint64_t} day - highest daily number of actions
  • {uint64_t} week - highest weekly number of actions
  • {time_point_sec} last_updated - last updated (UTC)

example

{
  "hour": 875365,
  "day": 20773084,
  "week": 83237200,
  "last_updated": "2019-11-03T16:48:21"
}
You can’t perform that action at this time.