I'm trying to understand ERC20 tokens. This page indicates that we can implement merged mining with the following code:

function giveBlockReward() { balanceOf[block.coinbase] += 1; }

  1. Newbie question: Someone will have to pay to call this function, right? Is there a way for the contract to call it automatically?

I've seen that the following code needs to be added to prevent abuses (source: Are mineable tokens possible?)

uint lastBlockRewarded; function giveBlockReward() { if (lastBlockRewarded >= block.number) throw; lastBlockRewarded = block.number; balanceOf[block.coinbase] += 1; }

  1. If the function isn't called for a few blocks, then called for the last one, some blocks will be lost?


1 Answer 1


1) there's no way for the contract to be called automatically, so yup for the "merged mining" to be working, the miner has to call the contract once a block is mined to get the token reward.

2) yes if the function is not called for each block mined, then no token will be "mined" for those blocks.

of course you can use

balanceOf[block.coinbase] += block.number - lastBlockRewarded;

to reward all thte "lost" tokens to whoever mined the last block at the time of the calling of the contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.