0

I have an ERC20 token which is already deployed on the mainnet. I want to make a contract which accepts this token from users and pays dividends in Ethereum stored already inside the contract. In my knowledge, ERC20 doesn't have a default tokenfallback function. So how will I detect the incoming token transaction to my contract?

1

You don't.

That's actually the biggest drawback of the ERC20 token standard, and that's why ERC777 tokens were invented. Everyone should be using ERC777 tokens instead.

The correct way of accepting ERC20 tokens is to use the approve => transferFrom pattern.

First, the sender sends an approve message to the ERC20 contract, where the sender approves your contract to transfer funds.

Second, the send calls your contract, which is now approved by the ERC20 token, so that your contract can use transferFrom on the ERC20 token, and transfer funds to itself (or someone else).

Tokens sent directly to a contract using the transfer method (which is not the correct way of doing it) will be PERMANENTLY LOCKED in that contract!

| improve this answer | |
0

The transaction is sent to the ERC20 contract, not to your contract.

The ERC20 contract maintains a record of how many tokens are owned by your contract.

As a result of the transfer, this record within the ERC20 contract is updated.

Holding tokens is more like putting your money in a bank rather than keeping it in your wallet.

That bank maintains a ledger which indicates how much money each client owns at any given moment.

| improve this answer | |
  • Yeah I know that. What I was asking is, my user is sending token to my contract. Which means the receiver is my contract. How can I make my contract to detect this incoming token transaction. I know there is a tokenfallback function on erc223, but my token is an already deployed erc20 – Aceson Oct 8 at 6:04

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.