1

I noticed that the callTokensReceived hook is called when using a few of the ERC777 functions but I am wondering how this could be triggered if an ERC20 token was sent to it?

Example (pseudo code):

  1. Users runs erc20.transfer(erc777.address)
  2. erc777receiverHook triggers someFunction() which references the erc20 token and its sender

Would the ERC777 contract have to be approved/given an allowance and then the ERC777 can use the transferFrom function to withdraw tokens to the contract which would trigger the callTokensReceived?

I can't imagine that would be the approach because a big advantage in using ERC777 is to remove this two step approve/transferFrom method.

0

holder

Token holder. The holder can “authorize” and “revoke” operators which can send tokens on their behalf. These operators are intended to be verified contracts such as an exchange, a cheque processor or an automatic charging system.

operator

An operator is an address which is allowed to send and burn tokens on behalf of some holder.

from docs:

The tokensReceived hook allows to send tokens to a contract and notify it in a single transaction, unlike ERC-20 which requires a double call (approve/transferFrom) to achieve this.

The holder can “authorize” and “revoke” operators which can send tokens on their behalf. These operators are intended to be verified contracts such as an exchange, a cheque processor or an automatic charging system.

ERC-20 compatibility requirement

The decimals of the token MUST always be 18. For a pure ERC777 token the ERC-20 decimals function is OPTIONAL, and its existence SHALL NOT be relied upon when interacting with the token contract. (The decimal value of 18 is implied.) For an ERC-20 compatible token, the decimals function is REQUIRED and MUST return 18. (In ERC-20, the decimals function is OPTIONAL. If the function is not present, the decimals value is not clearly defined and may be assumed to be 0. Hence for compatibility reasons, decimals MUST be implemented for ERC-20 compatible tokens.)

If the token implements ERC-20, it MUST register the ERC20Token interface with its own address via ERC-1820. This is done by calling the setInterfaceImplementer function on the ERC1820 registry with the token contract address as both the address and the implementer and the keccak256 hash of ERC20Token (0xaea199e31a596269b42cdafd93407f14436db6e4cad65417994c2eb37381e05a) as the interface hash.

conclusion

Yes, if an operator is approved to spend on behalf of the holder, on tokensReceived, it can be transferred immediately. operatorSend defined in the interface sends the amount of tokens on behalf of the address from to the address to.

2
  • So when you say "operatorSend defined in the interface sends the amount of tokens on behalf of the address from to the address to" do you mean that tokens can be sent that are either ERC20 or ERC777? Because ideally I would like operators to transfer ERC20 tokens on behalf of a user AND trigger a tokensReceived hook. From what I read it seems like operators can only manage tokens of the ERC777 contract, not other tokens like ERC20 Apr 14 at 11:13
  • @B537B7725DC58715F6E6BFA7AFC20C i have updated my answer
    – hack3r_0m
    Apr 14 at 14:55

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.