question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ERC20 contract loses tokens sent to the contract's own address

See original GitHub issue

🧐 Motivation Many people lose their ERC20 tokens by mistakenly sending their tokens back to the token contract address (presumably to redeem their tokens). However, there is no way to recover those tokens. https://np.reddit.com/r/ethereum/comments/sfz4kw/did_i_just_lose_half_a_million_dollars_by_sending/

📝 Details ERC20 implementation should reject such transfers. For example, we may add a require statement to the _transfer function in ERC20.sol.

    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal virtual {
        ...
        require(recipient != address(this), "ERC20: transfer to the token contract address");
        ...
    }

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Amxxcommented, Feb 2, 2022

Hello @duckki

The ERC20 standard doesn’t prevent sending tokens to the contract itself, and there might be legitimate use-cases where users lock/stake their tokens that result in the contract transferring them to itself. I’ve also seen ERC20+ICO combo contracts where the tokens are minted and given to the contract itself, and can then be bought for ETH.

So I don’t think we should include that by default for everyone.

On the other hand, we do encourage users to add these mechanisms, if they ever need it … and we make that easy for them:

contract MyToken is ERC20 {
    constructor() ERC20("MyToken", "MTK") {}

    function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        require(recipient != address(this));
        super._transfer(sender, recipient, amount);
    }
}
0reactions
qbzztcommented, Jun 9, 2022

I think a comment in the code will help. I’ll submit a PR to that effect.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I accidentally sent a token to a token contract. Can I get it back?
If you sent a token to a contract address there's no way to get them back even if the contract's owner wanted. Unless...
Read more >
How to prevent stuck tokens in contracts - Solidity developer
Just take a look at following token contracts. Those are all ERC-20 contracts where users sent the token directly to the contract itself,...
Read more >
Prevent transferring Ethereum Tokens to 0x0 and your ...
are just stuck at the contract address. However, those locked EOS tokens will be claimed once the network is lunched according to their...
Read more >
Blockchain enthusiast allegedly loses $500K by sending ...
Instead, the anonymous Reddit user sent the wETH directly back into the wETH smart contract address in the hopes of receiving ETH back....
Read more >
Mistake Costs User $1.1 Million in AAVE - Decrypt
An AAVE holder mistakenly sent $1.1 million worth of the DeFi token to the token's smart contract address. · The mistake means that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found