When I use the function approveAndCall on my Token contract (ropsten) and Metamask is triggered, my token name and value do not appear, only the gas calculation.

  • I have added a custom token to Metamask.
  • The token appears when I use the approve() or transferFrom() functions.
  • The problem persists in solidity and web3.js

The spender is a service contract and the part of code that completes the action from token contract is:

contract tokenRecipient {
    event receivedTokens(address _from, uint256 _value, address _token);

    function receiveApproval(address _from, uint256 _value, address _token) public; 

interface Token {
    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);

mapping (address => uint256) public payers;

function receiveApproval(address _sender, uint256 _value, address _tokenContract, bytes param) public {
    Token t = Token(_tokenContract);
    require(t.transferFrom(_sender, this, _value));
    payers[_sender] += _value;
    receivedTokens(_sender, _value, _tokenContract);

Now the part of Token contract:

function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
    allowed[msg.sender][_spender] = _value;
    Approval(msg.sender, _spender, _value);      
    if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) {
    return true;

The execution is successful, the tokens arrive at the destination, everything is ok, except the token name and value in Metamask.

image with problem

I am new to coding so maybe some basic things are missing. Thanks!

  • I have used another token contract to test if the approveAndCall from service contract is the problem, i have added the new tokens of new token contract in Metamask and tested again the approveAndCall function, same issue, the token name and value are not appearing in Metamask but the transfer is successful make. Than the problem is from receive Approval from service contract. I think this issue can make some hackers to take tokens from users without they now they accept an token transfer in mainnet. – sniper Jan 6 at 14:19

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.