0

From my base address I created a contract standard ERC20 token but I forgot add the distribute function so I made a new more contract like this:

pragma solidity ^0.4.16;

contract Owned {
        address public owner;

        function owned() {
            owner = msg.sender;
        }

        modifier onlyOwner {
            require(msg.sender == owner);
            _;
        }

        function transferOwnership(address newOwner) onlyOwner {
            owner = newOwner;
        }        
}



contract BatchToken is Owned {
    mapping (address => uint256) public balanceOf;      

    event Transfer(address indexed from, address indexed to, uint256 value);


    function distributeToken(address[] addresses, uint256 _value) onlyOwner {
        for (uint i = 0; i < addresses.length; i++) {
            balanceOf[owner] -= _value;
            balanceOf[addresses[i]] += _value;
            Transfer(owner, addresses[i], _value);
        } 
    }

    function Destroy() onlyOwner() {
        selfdestruct(owner);
    }
}

Then I send the token from Token contract to this contract and run distribute, it's working ok. But the problem is: token receive show as no name. Please check this out

1

Totally unrelated to your question at all, BUT, please review your code.

function owned() {
            owner = msg.sender;
        }

owned should be named Owned if it is meant to be the contract's constructor. Otherwise, anyone will be able to call this function and become the owner of your token contract. This is a serious vulnerability.

  • :( i'm new with this, so how to fix this code if I want only owner can run the function on my contract? – Liam Hoang Nov 3 '17 at 18:27
  • ethereum.org/token#the-code I'm flowing this tutorial, so you mean this code is vulnerability too? – Liam Hoang Nov 3 '17 at 18:29
  • 1
    No, as the name of the contract and the constructor are both lowercase unlike in your contract. – radek1st Nov 4 '17 at 21:41

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.