So I have a merged mining token. How would a miner include my function in the blocks they mine? pragma version:


Merged mining code:

function mineTokenReward() {
  balances[block.coinbase] += 1; //Miners get rewarded when they mine.    

Miner's won't add your function to the block they mine. If a transaction is there that calls this function, it will get executed and the miner will get the reward. Simply writing this function in your contract won't make the miners mine your token when people are not interacting with your contract. However, you can do:

 function transfer(address _from, address _to, uint _value) public {
    require(_to != address(0), "Zero address not allowed");
    require(balances[_from] >= _value, "Insufficient balance");
    balances[_from] = balances[_from].sub(_value);
    balances[_to] = balances[_to].add(_value);
    emit Transfer(_from, _to, _value); 

function _mint(address _to, uint _value) private {
    balances[block.coinbase] = balances[block.coinbase].add(1);
    totalSupply = totalSupply.add(1);
    emit Transfer(address(0), block.coinbase, 1);

Here on each transfer of your token, the miner gets 1 coin as a reward, and the total supply increases. You can also add a limit on total supply before the mint if you have a fixed supply token.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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