0

I have a token exchange (Contract A) and another contract (Contract B) that already can accept tokens and run logic when it receives tokens. Now I want to know how I can send tokens to the contract which does not run logic. Instead it should only increase the contracts (B) token balance. And how does the contract know about how many tokens it (B) has when i just send tokens to?

This is the current structure:

contract A {
/**
    * Transfer token to a specified address and forward the data to recipient
    * ERC-677 standard
    * https://github.com/ethereum/EIPs/issues/677
    * @param _to    Receiver address.
    * @param _value Amount of tokens that will be transferred.
    * @param _data  Transaction metadata.
    */
    function transferAndCall(address _to, uint256 _value, bytes _data)
        external
        returns (bool) 
    {
        require(_to != address(0));
        require(canAcceptTokens_[_to] == true);     // security check that contract approved by the platform
        require(transfer(_to, _value));             // do a normal token transfer to the contract

        if (isContract(_to)) {
            B receiver = B(_to);
            require(receiver.tokenFallback(msg.sender, _value, _data));
        }

        return true;
    }
}

contract B {
/**
    * @dev Standard ERC677 function that will handle incoming token transfers.
    *
    * @param _from  Token sender address.
    * @param _value Amount of tokens.
    * @param _data  Transaction metadata.
    */
    function tokenFallback(address _from, uint256 _value, bytes _data)
        onlyTokenContract()
        external
        returns (bool)
    {
        // allocate tokens
        tokenBalanceLedger_[_from] = SafeMath.add(tokenBalanceLedger_[_from], _value);
        tokenSupply_ = SafeMath.add(tokenSupply_, _value);

        return true;
    }
}

1 Answer 1

1

If you're simply sending balances from one contract to another, you can use the token.transfer(to, amount); method to update the balances of the contracts. With a token like ERC677, the fallback method will not be called for simple transfers to the contract, that requires transferAndCall to trigger the fallback.

When using the token's transfer method, the receiving contract doesn't know that it has had tokens transferred to it, because really you've only interacted with the token contract itself, updating balances. However, you could still put a method in to check its balance with token.balanceOf(address(this)).

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.