Querying Block Rewards⚓︎
Each block on NEM is produced by a single harvester account. The entire reward for harvesting a block comes from the transaction fees collected in that block, and these fees are paid in full to the harvester that produced it.
This tutorial shows how to query any block, identify its harvester, and sum the transaction fees that form the reward.
Prerequisites⚓︎
Before you start, set up your development environment.
This tutorial only reads data from the network. No account or XEM balance is required.
Full Code⚓︎
The snippet uses the NODE_URL environment variable to set the NEM API node.
If no value is provided, a default testnet node is used.
The BLOCK_HEIGHT environment variable selects which block to query.
If not set, it defaults to 661258, a block harvested on testnet.
Code Explanation⚓︎
The code fetches a block by height and derives the harvester address from the block's signer public key. It then sums the fees of every transaction in the block to obtain the total reward.
Fetching Block Information⚓︎
The /block/at/public POST endpoint returns information about the block at the requested height,
including the list of transactions present in the block.
Identifying the Harvester⚓︎
The signer field holds the public key of the account that harvested the block.
The method converts this public key into the corresponding testnet address.
The signer is not always the account that earns the reward
With local harvesting, the signer is the harvester account and receives the reward.
With remote harvesting or delegated harvesting, the signer is a remote account, while the
reward is paid to the main account.
Summing the Transaction Fees⚓︎
Each transaction in the block has a fee field expressed in atomic units.
XEM has a divisibility of 6, so 350000 atomic units represent 0.350000 XEM.
Adding the fees of every transaction gives the total reward for the block.
Calculating the Total Reward⚓︎
The total block reward equals the sum of all transaction fees, paid in full to the harvester. An empty block has no fees, and therefore no reward.
Alternative: Query rewards by account
This tutorial calculates the reward for a specific block by summing the transaction fees it contains.
If you are interested in the rewards earned by a particular account instead, use the
/account/harvests GET endpoint.
It returns one entry per harvested block, including a totalFee field with the reward earned for that block.
The endpoint accepts the address of the harvester account, the account that earns the reward. With remote harvesting or delegated harvesting, that is the main account, not the remote account that signed.
A remote account address also returns the blocks it signed on behalf of the main account.
Output⚓︎
The following output shows a typical run querying the rewards for block 661,258:
Some highlights from the output:
- Harvester (line 4): The address derived from the block's
signerpublic key. - Transaction fees (lines 7 to 8): The fee paid by each transaction included in the block.
- Total block reward (line 10): The sum of all transaction fees paid in full to the harvester.
Conclusion⚓︎
This tutorial showed how to:
| Step | Related documentation |
|---|---|
| Fetch block information | /block/at/public POST |