7

Does anyone know how to correctly implement the new ERC777 token standard? I've been trying to create an ERC777 contract (see code below) but keep struggling with a couple of things.

  1. According to the standard, recipient addresses must match the ITokenRecipient interface as returned by an ERC-672 reverse lookup. Any idea how to do this?
  2. There seems to be a fallback interface ITokenFallback that is not mentioned in the standard at all. How does 777 handle fallbacks (e.g. in case foreign tokens are sent to the contract)?
  3. The standard requires the usage of operatorData and userData but doesn't really say what to do with these values. Is it sufficient to include this data in the events that are defined in the 777 interface?

My ERC777 implementation so far:

contract MyToken is EIP777 {

string public name;            
uint8 public decimals;               
string public symbol;  
uint256 public totalSupply;
mapping (address => uint256) balances;
mapping (address => mapping (address => bool)) authorizedOperators;

function send(address _to, uint256 _value) returns (bool success) {
    if (balances[msg.sender] >= _value && _value > 0) {
        balances[msg.sender] -= _value;
        balances[_to] += _value;
        Send(msg.sender, _to, _value, msg.sender, null, null);
        return true;
    } else { return false; }
}

function send(address _to, uint256 _value, _userData bytes) returns (bool success) {
    if (balances[msg.sender] >= _value && _value > 0) {
        balances[msg.sender] -= _value;
        balances[_to] += _value;
        Send(msg.sender, _to, _value, msg.sender, _userData, null);
        return true;
    } else { return false; }
}

function operatorSend(address _from, address _to, uint256 _value, bytes _userData, bytes _operatorData) returns (bool success) {
    if (balances[_from] >= _value && _value > 0 && isOperatorAuthorizedFor(msg.sender, _from) ) {
        balances[_to] += _value;
        balances[_from] -= _value;
        Send(_from, _to, _value, msg.sender, _userData, _operatorData);
        return true;
    } else { return false; }
}

function balanceOf(address _owner) constant returns (uint256 balance) {
    return balances[_owner];
}

function authorizeOperator(address _operator, bool _authorized) public {
    authorizedOperators[msg.sender][_operator] = _authorized;
    AuthorizeOperator(msg.sender, _operator, _authorized);
}

function isOperatorAuthorizedFor(address _operator, address _tokenHoler) public constant returns (bool) {
    return authorizedOperators[_tokenHoler][_operator];
}

}

I did some research and stumbled upon YogaToken. However, it uses ERC672 and a more complex implementation of authorizedOperators which adds globallyAuthorizedOperators and a doSend() function. It doesn't implement ITokenRecipient, either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.