Solidity theorytheory 0/50 · 0%
Interfaces · easy

19. Interfaces and abstract contracts

Talking to contracts you did not write.

An `interface` declares external function signatures with no implementation and no state — perfect for calling an existing contract such as an ERC-20 token. An `abstract contract` may implement some functions and leave others unimplemented.

interface IERC20 {
    function transferFrom(address from, address to, uint256 v) external returns (bool);
    function balanceOf(address a) external view returns (uint256);
}

IERC20(token).transferFrom(msg.sender, address(this), amount);

Wrapping an address in an interface does not verify what is deployed there — validate addresses you accept.

Check your understanding

  1. 1. What can an interface not contain?

  2. 2. What does `IERC20(token)` do?

  3. 3. When do you use an abstract contract?