2

I have managed to create a registered Ethereum "Token" using Primarily the "how to" from the Frontier website. I intend to proceed with a crowdsource ing contract to raise funds for what will be a fundraising event capable of doing some good in the world, but more on that later. The token creation text includes this suggestion for improving the functionality of my new token: You could for example reward ethereum miners, by creating a transaction that will reward who found the current block:

mapping (uint => address) miningReward;
function claimMiningReward() {
if (miningReward[block.number] == 0) {
 coinBalanceOf[block.coinbase] += 1;
 miningReward[block.number] = block.coinbase;
  }
}

simply pasting this code into my contract naturally produces error messages.

Q: What do I need to tweak, enter, change, to make it possible to reward minors with one of my tokens? for each and every mined new block. Thank you.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
DrSluice
  • 21
  • 2

2 Answers2

0

You can copy and paste your code snippet into the token contract. It will look like that:

contract token { 
    mapping (address => uint) public coinBalanceOf;
    event CoinTransfer(address sender, address receiver, uint amount);

    /* Initializes contract with initial supply tokens to the creator of the contract */
    function token(uint supply) {
        if (supply == 0) supply = 10000;
            coinBalanceOf[msg.sender] = supply;
    }

    /* Very simple trade function */
    function sendCoin(address receiver, uint amount) returns(bool sufficient) {
        if (coinBalanceOf[msg.sender] < amount) return false;
        coinBalanceOf[msg.sender] -= amount;
        coinBalanceOf[receiver] += amount;
        CoinTransfer(msg.sender, receiver, amount);
        return true;
    }

    mapping (uint => address) miningReward;

    /* Reward Ethereum block miner with a token */
    function claimMiningReward() {
        if (miningReward[block.number] == 0) {
            coinBalanceOf[block.coinbase] += 1;
            miningReward[block.number] = block.coinbase;
        }
    }
}
Paweł Bylica
  • 3,780
  • 1
  • 31
  • 44
0

I dont know if you figured this out yet. Anyone else having the same issue try the following snippet:

contract MyToken { 
    /* Public variables of the token */
    string public name;
    string public symbol;
    uint8 public decimals;

    /* This creates an array with all balances */
    mapping (address => uint256) public balanceOf;

    /* This generates a public event on the blockchain that will notify clients */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /* Initializes contract with initial supply tokens to the creator of the contract */
    function MyToken(uint256 _supply, string _name, string _symbol, uint8 _decimals) {
        /* if supply not given then generate 1 million of the smallest unit of the token */
        if (_supply == 0) _supply = 1000000;

        /* Unless you add other functions these variables will never change */
        balanceOf[msg.sender] = _supply;
        name = _name;     
        symbol = _symbol;

        /* If you want a divisible token then add the amount of decimals the base unit has  */
        decimals = _decimals;
    }

    /* Send coins */
    function transfer(address _to, uint256 _value) {
        /* if the sender doenst have enough balance then stop */
        if (balanceOf[msg.sender] < _value) throw;
        if (balanceOf[_to] + _value < balanceOf[_to]) throw;

        /* Add and subtract new balances */
        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;

        /* Notifiy anyone listening that this transfer took place */
        Transfer(msg.sender, _to, _value);
    }
}            

Then adding your code to reward the miners but changing "coinBalanceOf" with "balanceOf" like so:

mapping (uint => address) miningReward;

function claimMiningReward() {
    if (miningReward[block.number] == 0) {
        balanceOf[block.coinbase] += 1;
        miningReward[block.number] = block.coinbase;
    }
}

So Your final contract would look like this:

contract MyToken { 
    /* Public variables of the token */
    string public name;
    string public symbol;
    uint8 public decimals;

    /* This creates an array with all balances */
    mapping (address => uint256) public balanceOf;

    /* This generates a public event on the blockchain that will notify clients */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /* Initializes contract with initial supply tokens to the creator of the contract */
    function MyToken(uint256 _supply, string _name, string _symbol, uint8 _decimals) {
        /* if supply not given then generate 1 million of the smallest unit of the token */
        if (_supply == 0) _supply = 1000000;

        /* Unless you add other functions these variables will never change */
        balanceOf[msg.sender] = _supply;
        name = _name;     
        symbol = _symbol;

        /* If you want a divisible token then add the amount of decimals the base unit has  */
        decimals = _decimals;
    }

    /* Send coins */
    function transfer(address _to, uint256 _value) {
        /* if the sender doenst have enough balance then stop */
        if (balanceOf[msg.sender] < _value) throw;
        if (balanceOf[_to] + _value < balanceOf[_to]) throw;

        /* Add and subtract new balances */
        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;

        /* Notifiy anyone listening that this transfer took place */
        Transfer(msg.sender, _to, _value);
    }

    mapping (uint => address) miningReward;

    function claimMiningReward() {
        if (miningReward[block.number] == 0) {
            balanceOf[block.coinbase] += 1;
            miningReward[block.number] = block.coinbase;
        }
    }

} 
Clay Allen
  • 55
  • 2
  • 9