2

enter image description here

Why do i get this error message?

Code:

pragma solidity 0.4.8;

contract Adminstrator {
  address public admin;

  function Adminstrator() {
    admin = msg.sender;

    modifier onlyAdmin() { 
        if (msg.sender != admin) throw; 
        _; 

    }   
  }

  function transferAdminstrator(address newAdmin) onlyAdmin {
    admin = newAdmin; 
  }
}



contract Token {
  mapping (address=>uint256) public balanceOf;
  string public name;
  string public symbol;
  uint8 public decimal;
  uint256 public totalSupply;
  event Transfer(address indexed from, address indexed to, uint256 value);
  function Token(uint256 initalSupply, string tokenName, string tokenSmybol, uint8 decimalUnits) {
  balanceOf(msg.sender) = initalSupply;
  totalSupply = initalSupply;
  decimal = decimalUnits;
  symbol = tokenSmybol;
  name = tokenName;

}

function Transfer(address _to, uint256 _value) {
  if (balanceOf[msg.sender] < _value) throw;

  if (balanceOf[_to] + _value) < balanceOf[_to]) throw;

  balanceOf[msg.sender] -= _value;
  balanceOf[_to] += _value;
  Transfer(msg.sender, _to, _value);
  }
}

contract AssetToken is Adminstrator, Token {

  function AssetToken(uint256 initalSupply, string tokenName, string tokenSmybol, uint8 decimalUnits, address centralAdmin) Token(0, tokenName, tokenSmybol, decimalUnits) {
    totalSupply = initalSupply;
    if(centralAdmin != 0) {
        admin = centralAdmin;
    }
    else
    {
        admin = msg.sender;
    }
    balanceOf[admin] = initalSupply;
    totalSupply = initalSupply;
    }

    function mintToken(address target, uint256 mintedAmount) onlyAdmin{
        balanceOf[target] += mintedAmount;
        totalSupply += mintedAmount;
        Transfer(0, this, mintedAmount);
        Transfer(this, target, mintedAmount);
    }

    function Transfer(address _to, uint256 _value) {
        if (balanceOf[msg.sender] < _value) throw;
        if (balanceOf[msg.sender] < 0) throw;
        if (balanceOf[_to] + _value) < balanceOf[_to]) throw;

        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;
        Transfer(msg.sender, _to, _value);
    }
} 
1

The modifier should not be defined inside a function and also there are few other small issues in your contract, which are to be fixed.

I've made some changes, please check below code. I'm able to compile it in remix -

pragma solidity 0.4.8;

contract Adminstrator {
  address public admin;

  modifier onlyAdmin() { 
        if (msg.sender != admin) throw; 
        _; 

  } 

  function Adminstrator() {
    admin = msg.sender;
  }

  function transferAdminstrator(address newAdmin) onlyAdmin {
    admin = newAdmin; 
  }
}


contract Token
    {
    mapping (address=>uint256) public balanceOf;
    string public name;
    string public symbol;
    uint8 public decimal;
    uint256 public totalSupply;
    event TransferBal(address indexed from, address indexed to, uint256 value);

    function Token(uint256 initalSupply, string tokenName, string tokenSmybol, uint8 decimalUnits) {
        balanceOf[msg.sender] = initalSupply;
        totalSupply = initalSupply;
        decimal = decimalUnits;
        symbol = tokenSmybol;
        name = tokenName;
    }

    function Transfer(address _to, uint256 _value) {
        if (balanceOf[msg.sender] < _value) throw;

        if ((balanceOf[_to] + _value) < balanceOf[_to]) throw;

        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;
        TransferBal(msg.sender, _to, _value);
    }
}

contract AssetToken is Adminstrator, Token {

  function AssetToken(uint256 initalSupply, string tokenName, string tokenSmybol, uint8 decimalUnits, address centralAdmin) Token(0, tokenName, tokenSmybol, decimalUnits) {
    totalSupply = initalSupply;
    if(centralAdmin != 0) {
        admin = centralAdmin;
    }
    else
    {
        admin = msg.sender;
    }
    balanceOf[admin] = initalSupply;
    totalSupply = initalSupply;
    }

    function mintToken(address target, uint256 mintedAmount) onlyAdmin{
        balanceOf[target] += mintedAmount;
        totalSupply += mintedAmount;
        TransferBal(0, this, mintedAmount);
        TransferBal(this, target, mintedAmount);
    }

    function Transfer(address _to, uint256 _value) {
        if (balanceOf[msg.sender] < _value) throw;
        if (balanceOf[msg.sender] < 0) throw;
        if ((balanceOf[_to] + _value) < balanceOf[_to]) throw;

        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;
        TransferBal(msg.sender, _to, _value);
    }
} 

Hope this helps.

| improve this answer | |
0

It's because your modifier is inside a function. It needs to outside.

Not like this.

contract Adminstrator {
  address public admin;

  function Adminstrator() {
    admin = msg.sender;

    // it can't be inside this function
    modifier onlyAdmin() { 
      if (msg.sender != admin) throw; 
      _;
    } 
}   

Like this:

contract Admin {
   modifier onlyAdmin() {
     // check admin
     _;
   }
}

Then use it like:

function X() onlyAdmin {
  // do something after the check
}

Hope it helps.

| 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.