Answer the question
In order to leave comments, you need to log in
What is the smart contract interface for?
Greetings. Colleagues, what is the smart contract interface for?
pragma solidity ^0.5.0;
/**
* @title ERC20 interface
* @dev see https://eips.ethereum.org/EIPS/eip-20
*/
interface IERC20 {
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
Answer the question
In order to leave comments, you need to log in
An interface is required to call any contract function from a client or another contract.
The call includes the method signature - the first 4 bytes of the hash from the name of the function and its parameters (without a return value).
In most cases, you have the entire contract and there is no need to separate the interface.
The interface can help unify the code, and is also useful where the implementation of the contract is not exactly known - for example, you need to work with any tokens that support ERC20.
Another interface will be useful for all sorts of dirty hacks with fallback functions and delegatecall (proxy) - when the call goes through an intermediate contract.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question