SubQuery powers the next generation of Polkadot dApps by allowing developers to extract, transform and query blockchain data in real time using GraphQL. In addition to this, SubQuery provides production quality hosting infrastructure to run these projects in.
This subquery indexes staking bonds, rewards and slashes of each finalized blocks.
This is an example of EventHandler that provides records of all the accounts that have participated in staking and summarizes their total rewards and slashes. It also provides the total earnings.
git clone https://github.com/subquery/subql-examples.git
cd sum-reward
# Yarn
yarn
#NPM
npm install
#Yarn
yarn codegen
#NPM
npm run-script codegen
#Yarn
yarn build
#NPM
npm run-script build
#Yarn
yarn start:docker
#NPM
npm run start:docker
{
query{
stakingRewards{
nodes{
balance
}
}
}
}
{
query{
stakingSlashes{
nodes{
balance
}
}
}
}
{
query{
sumRewards{
nodes{
rewards{
nodes{
balance
}
}
}
}
}
}