1

I've been following this wiki as a reference. The code has this snippet:

// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
    return ERC20Interface(tokenAddress).transfer(owner, tokens);
}

Can someone explain the syntax and purpose of this method? Does this allow the owner to take back tokens from any stakeholders?

1

Many token contracts have an issue where people accidentally send various tokens to the token contract, instead of using the transfer method to send them to the actual destination.

In most cases, this effectively burns the tokens, since there is no way to retrieve them from a contract that doesn't support them.

These days, some authors have started adding token recovery methods that allow them to retrieve "stuck" tokens from the contract.

In your example, only tokens sent to the contract can be moved, and it cannot alter user balances.

1

This function is used when other people accidentally send a contract an ERC20 token.

Some people believe that they might be able to "trade" tokens or something by sending your contract ERC20 tokens rather than ETH. Without this function, those ERC20 tokens would be lost forever, since the owner of the tokens would now be the contract, and no one has access to the contract's private key.

So instead, this function allows the owner of the smart contract to send any of those 'lost' ERC20 tokens directly to their account.

This function demonstrates how an standard token format like ERC20 can be so useful, since this function takes advantage of the fact that all ERC20 tokens will have a transfer function which can be interacted with the same way.

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.