0

Instead of showing tokens the output shows Internal transactions or just contract interactions. what changes are needed to transfer tokens to any other ERC223 receiver contract?

  function transfer(address _to, uint256 _value)public returns (bool success){

    if(isContract(_to)){
        return transferToContract(_to, _value, "0x0");
    }
    else{
        return transferToAddress(_to,_value, "0x0");
    }
 }

 function transfer(address _to, uint256 _value, bytes memory _data)public returns(bool success){

    if(isContract(_to)){
        return transferToContract(_to, _value, "0x0");
    }
    else{
        return transferToAddress(_to, _value, "0x0");
    }
 }

 function isContract(address _addr) public view returns (bool is_contract) {
    uint length;
    assembly {
        length := extcodesize(_addr) 
    }
    return (length>0);
  }

 function transferToAddress(address _to, uint256 _value, bytes memory _data) public returns(bool success){
   require(balanceOf(msg.sender) > _value );
   balances[msg.sender] = balances[msg.sender].sub(_value);
   balances[_to] = balances[_to].add(_value);

   emit Transfer(msg.sender, _to, _value, _data);
   return true;       
 }

function transferToContract(address _to, uint256 _value, bytes memory _data) public returns(bool success){

    require(balanceOf(msg.sender) > _value );

    balances[msg.sender] = balances[msg.sender].sub(_value);
    balances[_to] = balances[_to].add(_value);

    ERC223ReceivingContract erc223Object = ERC223ReceivingContract(_to);
    erc223Object.tokenFallback(msg.sender, _value, _data);

    emit Transfer(msg.sender, _to, _value, _data);
    return true;
}

Is there any problem with the receiver contract solidity file? Here is the code of my Receiver Contract file.

contract ContractReceiver {

   address public sender;
   uint256 public value;
   bytes public data;

   function tokenFallback(address _to, uint256 _value, bytes memory _data) public {
     sender = _to;
     value = _value;
     data = _data;
    }
}
1

This is not an ERC223 contract.

ERC223 is an interface definition, so you have to use the function signatures defined in the interface to be an ERC223, by definition.

Have a look here: https://github.com/Dexaran/ERC223-token-standard/blob/master/token/ERC223/ERC223_interface.sol

Reference interface design:

contract ERC223Interface {
    uint public totalSupply;
    function balanceOf(address who) constant returns (uint);
    function transfer(address to, uint value);
    function transfer(address to, uint value, bytes data);
    event Transfer(address indexed from, address indexed to, uint value, bytes data);
}

Rather than transferToAddress and transferToContract there is only transfer with two function signatures. On execution, the EVM will select the appropriate function based on the number of inputs, selecting the second one if there is indeed a bytes data.

In terms of implementing the second version, it's expected (required actually) to invoke the receiving contract's tokenFallback function. This is for post-receipt processing on the receiving side (what to do in response to received tokens). You transferToContract seems to do that.

I'm not sure what you mean by:

Instead of showing tokens the output shows Internal transactions or just contract interactions

The expected behavior is a transaction receipt. The result is supposed to be tokens transferred to the receiver plus whatever happens in the receiver's tokenFallback function. Other than the transaction receipt, don't expect any further output from the node. This class of transaction is not special in that respect.

What you see when you explore the chain will vary according to the tools you use. Some, like Etherscan, will enumerate internal transactions. That is interpretation. Most likely you don't see token transfers because the block explorer you're using doesn't understand the non-standard function signatures of your contract. You need to resolve that with standards-compliant function signatures.

You would see, for example, an internal transaction from the token contract to the receiving contract's tokenFallback function but not necessarily any further details.

You should be able to see the receiving contract's balance increase and the sender's balance decrease with balanceOf(<address>) and if the receiving contract's tokenFallback function emits an event (probably should), then that as well.

Since there is no standard or limitation on what the receiving contract's tokenFallback function can/should do, you would have to inspect the contract state yourself to confirm the intended effects.

Hope it helps.

  • Thank you so much for this well described answer. I am totally agree with you in case of ERC223 standard's functions/ standard reference design that it (my code) should, include that in proper way. – Rudrika Feb 6 at 4:30
  • Here in my code I've included transferToContract and transferToAddress because I am checking if the _to address is an Address I'll call transferToAddress and if the _to address is a contract then I'll call transferToContract. And in this, Instead of showing tokens the output shows Internal transactions or just contract interactions I am using ropsten etherscan to view my transaction. The problem is, whenever I transfer tokens from one contract to another the etherscan doesn't reflect it that the Receiver _to address has this amount of tokens. – Rudrika Feb 6 at 4:33
  • Etherscan won't understand it because its not a compatible token contract and the function isn't called transfer. If balanceOf works as required then you can check internal workings manually. You still need to refactor for ERC223 standard. – Rob Hitchens B9lab Feb 6 at 4:57

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.

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