0

Actually, I wrote the code in multiple files, but since I need to Verify and Publish the code so, I tried to flatten the code. But now it is showing way too many errors. I put the code below with error messages in comments, can you guys please help me with the errors.

pragma solidity 0.4.25;

library SafeMath {

/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
  return 0;
}

uint256 c = a * b;
require(c / a == b);

return c;
}

/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // Solidity only automatically asserts 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;
}

 /**
 * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
 */
 function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;

return c;
}

/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);

return c;
}

/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
 function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
}


interface IERC20{        
function totalSupply() constant returns (uint256 totalSupply);
/**browser/ballot.sol:65:46: Warning: This declaration shadows an existing declaration.
function totalSupply() constant returns (uint256 totalSupply);
                                         ^-----------------^
browser/ballot.sol:65:5: The shadowed declaration is here:
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);
}

contract FuncToken is IERC20{

using SafeMath for uint256;

uint public constant _totalSupply = 0;

string public constant symbol = "UB";
string public constant name = "UNIFIED BET";
uint8 public constant decimals = 18;

//1 ether = 1 UB
uint256 public constant RATE = 1;

address public owner;

mapping (address => uint256) balances;
mapping (address => mapping(address => uint256)) allowed;

function () payable{
    createToken();
}

constructor (){
    owner = msg.sender;

}

function createToken() payable {
    require(msg.value > 0);

    uint256 tokens = msg.value;
    balances[msg.sender] = balances[msg.sender].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);
        /**browser/ballot.sol:126:13: Warning: Invoking events without "emit" prefix is deprecated.
        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].add(_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];
}

}

Any help will be appreciated. There are more errors with same warnings, but if you guys can let me know one, I'll fix others. All errors are in /** **/

1

These are mostly warnings, not errors.

To help you get going, the first thing you've commented is related to this:

interface IERC20{        
    function totalSupply() constant returns (uint256 totalSupply);
    /**browser/ballot.sol:65:46: Warning: This declaration shadows an existing 
    declaration.
    function totalSupply() constant returns (uint256 totalSupply);

And this:

function totalSupply() constant returns (uint256 totalSupply){
    return _totalSupply;
}

The problem being that your variable name is the same as your function name. Also in the second of these snippets you're using _totalSupply whereas the parameter you passed in is totalSupply, with no underscore.

Change to the following (with an underscore), or change the variable name to something else entirely to prevent confusion with the function name:

function totalSupply() constant returns (uint256 _totalSupply);

All the other warnings seem to be because you haven't specified visibilities on functions and variables. Take a look at the relevant section in the docs: Function Visibility Specifiers.

  • Thanks for the help. But why are the tokens issued isn't transferable and is not visible in etherscan, though it is visible in Metamask after adding the token? – Saumya Brata Dutt Oct 15 '18 at 16:03
0

1) simply add “emit” before the event invocation, because grammar changes after 0.4.23 if I’m not wrong, so there is not something to understand, jus add it

2) on the contrary the second error suggests that you have to go deeper in the lessons. I suggest you to have them clear: inheritance, public variables, implicit getter, scope of variables and functions. It is not useful to have just an answer here, if you want to go on with this development, I kindly think it is better to make a bit of research work more. It will be evident to yourself what needed!

Best wishes!

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.