1

I have a BuyToken event when user send ether to smart contract they will receive tokens based on ether amount. For ex: 1 ETH = 1000 Token.

/// This notifies clients about the Buy Token
event BuyToken(address user, uint256 eth, uint256 token);

There is my buy() function

 /**
*  function for Buy Token
*/

function buy() payable public returns (uint amount){
      require(msg.value > 0);

      amount = ((msg.value.mul(TokenPerETHBuy)).mul( 10 ** uint256(decimals))).div(1 ether);
      balanceOf[this] -= amount;                        // adds the amount to owner's 
      balanceOf[msg.sender] += amount; 
      emit BuyToken(msg.sender,msg.value,amount);
      return amount;
}

It works well when user send ether user will receive tokens.

But this transaction event is not visible on Etherscan.io

For ex: Ropsten link

I send 0.2 ether I receive 200 tokens. I can see ether transaction. But received tokens transaction not visible on "ERrc20 Token Txns" tab.

Pelase can you help ??

2

1 Answer 1

1

You have to emit the Transfer event for Etherscan to see it as a token transfer . Most people handle this by logging 0x0 as the from address.

3
  • Should I change BuyToken -> Transfer event ? Dec 12, 2018 at 2:08
  • You can emit both if you want, and you have to if you want to query for BuyToken events later.
    – natewelch_
    Dec 12, 2018 at 2:12
  • emit BuyToken(msg.sender,msg.value,amount); emit Transfer(msg.sender,this ,amount); Dec 12, 2018 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.