0

I've flattened the code and fixed the warning. But the problem with the contract is that the tokens are not visible in the addresses when searched with etherscan but when I try to add through Metamask, it is easily visible.

The second problem is the tokens aren't transferring. I don't know the reason for that too, there were Static Warnings but Gas, but I didn't understand that well.

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() external constant returns (uint256 tootalSupply);
function balanceOf(address _owner) external constant returns (uint256 baalance);
function transfer(address _to, uint256 _value) external returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);
function approve(address _spender, uint256 _value) external returns (bool success);
function allowance(address _owner, address _spender) external 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 () public{
    owner = msg.sender;

}

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

    uint256 tokens = msg.value;
    balances[msg.sender] = balances[msg.sender].add(tokens);

    owner.transfer(msg.value);
}

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

function balanceOf(address _owner) public constant returns (uint256 balance){
    return balances[_owner];
}

function transfer(address _to, uint256 _value) public returns (bool success){
    require (
        balances[msg.sender] >= _value
        && _value > 0
        );
        balances[msg.sender] = balances[msg.sender].sub(_value);
        balances[_to] = balances[_to].add(_value);
        emit Transfer(msg.sender, _to, _value);
        return true;

}

function transferFrom(address _from, address _to, uint256 _value) public 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);
        emit Transfer(_from, _to, _value);
        return true;
}

function approve(address _spender, uint256 _value) public returns (bool success){
    allowed[msg.sender][_spender] = _value;
    emit Approval(msg.sender, _spender, _value);
    return true;
}

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

}

Any help will be appreciated.

  • What is your token address? Do you have an example of transaction without events. In any case Etherscan is closed source third party and they might delay process of contracts for undisclosed reasons. – Ismael Oct 15 '18 at 16:37
  • currently deployed in Rinkeby Network. Contract Address - 0x0F051Af45eEdB54aA7d84a2aBF1829BAe82d026C – Saumya Brata Dutt Oct 15 '18 at 16:42
  • You said, "Tokens aren't transferring". if you try to transfer tokens using transfer function, what happens? any transaction hash, please? – Yogesh - EtherAuthority.io Aug 4 at 4:08
  • And "Tokens are not visible in etherscan". Firstly, its takes some time in etherscan. and secondly, there should be some transfer events occured to be picked up in search results in etherscan :) – Yogesh - EtherAuthority.io Aug 4 at 4:10
0

The token address pages states that no transfer event was registred https://rinkeby.etherscan.io/tokens?q=0x0F051Af45eEdB54aA7d84a2aBF1829BAe82d026C.

Now looking at your fallback function it calls createToken and that function doesn't generate an event.

To generate an event you have to modify your function to look like this:

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

    uint256 tokens = msg.value;
    balances[msg.sender] = balances[msg.sender].add(tokens);

    owner.transfer(msg.value);

    // --------- Generate Transfer event -------------
    emit Transfer(address(0x), msg.sender, tokens);
}
  • 1
    By first looking at your answer I was wondering "but the Transfer event is emitted right there" until I realized you had modified the original function for demonstration purposes. Could maybe make that more clear. – Lauri Peltonen Oct 16 '18 at 7:38

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.