0

I see the fallback function of a contract as a way of "depositing" an Ether value to the contract. My question is very simple I guess, but I couldn't find the answer yet.

Is it possible to develop a fallback function to deposit ERC20 tokens into a contract? What's the best way to deposit ERC20 tokens to a contract, VIA contract (by deposit I mean 'ownership transfer')? Like use the key payable but instead of sending ether, send ERC20 tokens.

  • 1
    That's not the purpose of a fallback function, and there is no equivalent payable keyword for tokens, since a Token (ERC20, for example) is a standard which is defined "one layer above the blockchain". Think of it as something like "Ether - hardware layer, Token - software level". Just implement the ERC20 standard functions, and they will allow you to do what you're asking. – goodvibration Sep 2 at 17:00
0

I suggest you use the new up to date erc20 standard call erc777. The erc777 is new and improve version of erc20 and it is still compatible with old erc20 contract. It has a tokenReceived function which the contract must register its on erc1820. It almost the same as the fallback ethereum function, if the balance of the registered address increases, execute that function on that address.

  • sorry @goodvibration i think i'm gonna fix it but it is a solution to solve the problem you send token to the contract and then the tokenReceived function on that contract will execute the code that change it state on that call (or not) – haxerl Sep 3 at 2:36
  • Depends how you implement the tokenReceived function, hence there is no difference from any other standard (in the sense that it's up to you to implement that). And in short, I don't see how it answers the question. – goodvibration Sep 3 at 6:21

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.