0

Below is the script that i have written but i cannot run it, i get some messages( the order of the messages that I post is first the ones i get for the IERC20 and then for the AAAtoken), first is the script for IERC20, the SafeMath, then i import those two to AAAtoken script

pragma solidity ^0.4.11;

interface IERC20 {

function totalSupply() constant returns (uint256 totalSupply);

    function balanceOf(address_owner) constant returns (uint256 balance);
    function transfer(address_to, uint256_value) returns(bool success);
    function transferFrom(address_from, address_to, uint256_value) returns(bool success);
    function approve(address_spender, uint256_value) returns(bool success);
    function allowance(address_owner, address_spender) constant returns(uint256 remaining);
    event Transfer(address indexed_from, address indexed_to, uint256_value);
    event Approval(address indexed_owner, address indexed_spender, uint256_value);


}

pragma solidity ^0.4.18;



/**
 * @title SafeMath
 * @dev Math operations with safety checks that throw on error
 */

library SafeMath {

  /**
  * @dev Multiplies two numbers, throws on overflow.
  */
  function mul(uint256 a, uint256 b) internal pure returns (uint256) {
    if (a == 0) {
      return 0;
    }
    uint256 c = a * b;
    assert(c / a == b);
    return c;
  }

  /**
  * @dev Integer division of two numbers, truncating the quotient.
  */

function div(uint256 a, uint256 b) internal pure returns (uint256) {
    // assert(b > 0); // Solidity automatically throws when dividing by 0
    uint256 c = a / b;
    // assert(a == b * c + a % b); // There is no case in which this doesn't hold
    return c;
  }

pragma solidity ^0.4.11;

import './IERC20.sol';
import './SafeMath.sol';

contract AAAtoken is IERC20{

    using SafeMath for uint256;

    uint public _totalSupply=0;
    string public constant symbol = "AAA";
    string public constant name= "AAA Token";
    uint8  public constant decimals = 18;

    // 1 Ether = 500 AAA
    uint256 public constant RATE = 500;
    address public owner;
    mapping(address=>uint256) balances;
    mapping(address=> mapping(address=> uint256)) allowed;


    function() payable {
        createTokens();

    }

    function AAAtoken(){
        owner=msg.sender;

    }

    function createTokens() payable {
        require(msg.value > 0);
        uint256 tokens = msg.value.mul(RATE);
        balances[msg.sender] = balances[msg.sender].add(tokens);
        _totalSupply = _totalSupply.add(tokens);
        owner.transfer(msg.value);

    }



    function totalSupply() constant returns (uint256 totalSupply){

        return _totalSupply;


    }
    function balanceOf(address_owner) constant returns (uint256 balance){

        return balances[_owner];


    }
    function transfer(address_to, uint256_value) returns(bool success){

        require(
            balances[msg.sender] >= _value
            && _value > 0
        );
        balances[msg.sender]=balances[msg.sender].sub(_value);
        balances[_to]=balances[_to].add(_value);
        Transfer(msg.sender, _to, _value);
        return true;


    }
    function transferFrom(address_from, address_to, uint256_value) returns(bool success){

        require(
            allowed[_from][msg.sender] >= _value
            && balances[_from] >= _value
            && _value >0

        );
        balances[_from] =balances[_from].sub(_value);
        balances[_to] =balances[_to].add(_value);
        allowed[_from][msg.sender] =allowed[_from][msg.sender].sub(_value);
        Transfer(_from, _to, _value);
    return true;


    }
    function approve(address_spender, uint256_value) returns(bool success){

        allowed[msg.sender][_spender] = _value;
        Approval(msg.sender, _spender, _value);
        return true;


    }
    function allowance(address_owner, address_spender) constant returns(uint256 remaining){
        return allowed[_owner] [_spender];


    }
        event Transfer(address indexed_from, address indexed_to, uint256_value);
        event Approval(address indexed_owner, address indexed_spender, uint256_value);







}


//Messages for the IERC20

browser/IERC20.sol:4:5: Warning: No visibility specified. Defaulting to "public".
    function totalSupply() constant returns (uint256 totalSupply);
    ^------------------------------------------------------------^

browser/IERC20.sol:5:5: Warning: No visibility specified. Defaulting to "public".
    function balanceOf(address_owner) constant returns (uint256 balance);
    ^-------------------------------------------------------------------^
browser/IERC20.sol:6:5: Warning: No visibility specified. Defaulting to "public".
    function transfer(address_to, uint256_value) returns(bool success);
    ^-----------------------------------------------------------------^
browser/IERC20.sol:5:24: DeclarationError: Identifier not found or not unique.
    function balanceOf(address_owner) constant returns (uint256 balance);
                       ^-----------^


//Messages for the AAAtoken

browser/AAAtoken.sol:22:5: Warning: No visibility specified. Defaulting to "public".
    function() payable {
    ^

Spanning multiple lines.

browser/AAAtoken.sol:27:5: Warning: No visibility specified. Defaulting to "public".
    function AAAtoken(){
    ^

Spanning multiple lines.

browser/AAAtoken.sol:32:5: Warning: No visibility specified. Defaulting to "public".
    function createTokens() payable {
    ^

Spanning multiple lines.

browser/AAAtoken.sol:43:5: Warning: No visibility specified. Defaulting to "public".
    function totalSupply() constant returns (uint256 totalSupply){
    ^

Spanning multiple lines.

browser/AAAtoken.sol:49:5: Warning: No visibility specified. Defaulting to "public".
    function balanceOf(address_owner) constant returns (uint256 balance){
    ^
Spanning multiple lines.

browser/AAAtoken.sol:55:5: Warning: No visibility specified. Defaulting to "public".
    function transfer(address_to, uint256_value) returns(bool success){
    ^
Spanning multiple lines.

browser/AAAtoken.sol:68:5: Warning: No visibility specified. Defaulting to "public".
    function transferFrom(address_from, address_to, uint256_value) returns(bool success){
    ^
Spanning multiple lines.

browser/AAAtoken.sol:84:5: Warning: No visibility specified. Defaulting to "public".
    function approve(address_spender, uint256_value) returns(bool success){
    ^
Spanning multiple lines.

browser/AAAtoken.sol:92:5: Warning: No visibility specified. Defaulting to "public".
    function allowance(address_owner, address_spender) constant returns(uint256 remaining){
    ^
Spanning multiple lines.

browser/IERC20.sol:4:46: Warning: This declaration shadows an existing declaration.
    function totalSupply() constant returns (uint256 totalSupply);
                                             ^-----------------^
browser/IERC20.sol:4:5: The shadowed declaration is here:
    function totalSupply() constant returns (uint256 totalSupply);
    ^------------------------------------------------------------^

browser/AAAtoken.sol:43:46: Warning: This declaration shadows an existing declaration.
    function totalSupply() constant returns (uint256 totalSupply){
                                             ^-----------------^
browser/AAAtoken.sol:43:5: The shadowed declaration is here:
    function totalSupply() constant returns (uint256 totalSupply){
    ^
Spanning multiple lines.

1 Answer 1

1

You have a bunch of missing spaces (address_owner instead of address _owner, uint256_value instead of uint256 _value, etc.).

I believe there's also a missing curly brace at the end of SafeMath, but that's probably just a copy/paste error. You're also missing add and sub from SafeMath.

7
  • i have corrected the issue with the space, the add and sub are there, just missed them while i was copying/pasting the code here. I still get theses warnings, "No visibility specified"
    – kos_tsak
    Feb 12, 2018 at 10:27
  • Those warnings can be ignored if you want, or you can fix them. (It's fairly clear how to do that from just reading the warning, but search for it on the web if you want.)
    – user19510
    Feb 12, 2018 at 10:31
  • Yes I got it, compiled and run
    – kos_tsak
    Feb 12, 2018 at 10:57
  • I checked the contract on ropsten.etherscan.io, i have succesfully sent to the address 0.5 ether but the ETH Balance is 0, do i need to do something further?
    – kos_tsak
    Feb 12, 2018 at 11:05
  • The balance of what is 0?
    – user19510
    Feb 12, 2018 at 11:14

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.