1

I try to search on ERC 223 receiving contract implementation online but most of them just providing the interface. I am wondering if it is possible to do something like this for ERC 223 receiving contract.

Eg: I send token from transfer function in the main token contract. And based on the value (probably sig of functions in the receiving contract and values), the functions in receiving contract is call from tokenFallback and if the functions fail halfway all transaction reverted.

contract ERC223Receiver {
    function tokenReceiveLogic1() internal {
        require(tokenReceiveAmount > 3);
        // logic here
    }

    function tokenReceiveLogic2() internal {
        require(tokenReceiveAmount > 1);
        // logic here
    }


    function tokenFallback(
        address _sender,
        uint256 _value,
        bytes _extraData) returns (bool) {
        if (condition 1) {
            // trigger tokenReceiveLogic1()
            // if tokenReceiveLogic1 fail halfway, revert all transaction
        } else if (condition 2) {
            // trigger tokenReceiveLogic1()
            // if tokenReceiveLogic1 fail halfway, revert all transaction
        }
    }
}
1

Yes. It is possible. Just check make sure that your fallback function require your condition to be met. You can also check in your main contract what is the value returned by fallback function and revert on this base. Example is below. In this example I am checking if value is greater than 10. If not then transaction fails.

contract ERC223Receiver {
    function tokenReceiveLogic1() internal {
        // require(tokenReceiveAmount > 3);
        // logic here
    }

    function tokenReceiveLogic2() internal {
        // require(tokenReceiveAmount > 1);
        // logic here
    }


    function tokenFallback(
        address _sender,
        uint256 _value,
        bytes _extraData) returns (bool) {

        require(_value > 10);
        return true;
        // if (_value <= 10) {
        //     return true;
        // } else {
        //     return false;
        // }
    }
}

contract Token {
    function transfer(address to, uint value) public {
        bytes memory empty;
        bool shouldFail = ERC223Receiver(to).tokenFallback(msg.sender,value,empty);
        // require(!shouldFail,'Fallback function failed');

    }
}
  • u understand it wrongly. I mean how can i trigger function 1 or function 2 in tokenFallback based on the function sig pass in transfer (how should i pass it)?? and require(_value > 10) should be inside function 1 and another require(_value > 1) should be inside function 2 instead of inside tokenFallback. The example u show does not take in triggering function 1 and function 2 as criteria and revert eveyrthing when function 1/function 2 fail – stackdisplay Nov 7 '18 at 7:59
  • Ok. Can you give me more details on "based on the function signature pass in transfer" ? You want to know how to read signature of the function which called your tokenFallback function ? I am a bit confused. – Rob Magier Nov 7 '18 at 18:37
  • When i call transfer from ERC 223 contract to transfer token to smart contract, it will trigger the tokenFallback function in ERC 223 Receiver Contract. It should trigger a specific function (eg function 1 or function 2) from tokenFallback function itself based on data pass in the transfer function and revert back everything if it fail. I supposed that it can be identify by function sig pass or anything else that indicate which function (function 1 or function 2) to trigger in tokenFallback. – stackdisplay Nov 8 '18 at 1:39

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.