I am fairly new to smart contract development and am still trying to figure out the whole sending ETH/tokens to a contract thing. In an article I saw the following example of a contract's terminate method which would refund all tokens in the contract to the owner:

function terminate(IERC20Basic[] tokens) external onlyOwner {
        // Transfer tokens to owner
        for(uint i = 0; i < tokens.length; i++) {
            uint256 balance = tokens[i].balanceOf(this);
            tokens[i].transfer(owner, balance);
        // Transfer Ether to owner and terminate contract

What I don't understand is - when the owner calls terminate what should they pass as tokens parameter? I would love to see a concrete example, it would help me wrap my head around it


ERC20 tokens are just contracts that keep track of balances, so to transfer tokens, you call the transfer method on one of those contracts.

This function can be read as:

"For each token smart contract, find the balance of this contract and then send the full balance to the owner."

To answer your question, what gets passed in is an array of addresses. Solidity implicitly casts those addresses and treats them as smart contracts implementing the IERC20Basic interface, which presumably is defined to include balanceOf and transfer, two standard ERC20 functions.

  • Just to make sure I understand, those token addresses are the addresses of token contracts, correct? – Andrey Jan 20 '18 at 7:37
  • Yes, that's right. – user19510 Jan 20 '18 at 7:39

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.