Standard Interface Detection Interface (TIP-6.1)
Simple summary
Creates a standard method to publish and detect what interfaces a smart contract implements.
Abstract
Herein, we standardize the following:
- How interfaces are identified
- How a contract will publish the interfaces it implements
Motivation
For some “standard interfaces” like the token interface, it is sometimes useful to query whether a contract supports the interface and if yes, which version of the interface, in order to adapt the way in which the contract is to be interacted with. This proposal standardizes the concept of interfaces and standardizes the identification (naming) of interfaces.
Specification
How interfaces are identified
For this standard, an interface is a set of function selectors as defined by the Solidity ABI. This a subset of Solidity’s concept of interfaces and the interface keyword definition which also defines return types, mutability and events.
We define the interface identifier as the XOR of all function selectors in the interface. This code example shows how to calculate an interface identifier:
Solidity
interface Solidity101 {
function hello() external pure;
function world(int) external pure;
}
contract Selector {
function calculateSelector() public view returns (bytes4) {
Solidity101 i;
return bytes4(tvm.functionId(i.hello) ^ tvm.functionId(i.world));
}
}
How a Contract will Publish the Interfaces it Implements
A contract that is compliant with TIP6.1 shall implement the following interface:
Solidity
interface TIP6 {
/// @notice Query if a contract implements an interface
/// @param interfaceID The interface identifier, as specified in TIP6.1
/// @dev Interface identification is specified in TIP6.1.
/// @return `true` if the contract implements `interfaceID` and
/// `interfaceID` is not 0xffffffff, `false` otherwise
function supportsInterface(bytes4 interfaceID) external view responsible returns (bool);
}
The interface identifier for this interface is 0x3204EC29
. You can calculate this by running tvm.functionId('supportsInterface(bytes4)')
; or using the Selector contract above.
Therefore, the implementing contract will have a supportsInterface
function that returns:
true
wheninterfaceID
is0x3204EC29
(TIP6.1 interface)false
wheninterfaceID
is0xffffffff
true
for any otherinterfaceID
this contract implementsfalse
for any otherinterfaceID
References
The original TIP-6.1 standard was developed and maintained by the Everscale network community.