ZTP165 provides a protocol standard similar to ZEP165 and ERC165 for detecting smart contract interfaces on the ZTP blockchain. It specifies how smart contracts can declare and validate their supported interfaces, ensuring compatibility and ease of integration between different smart contracts.
The ZTP165 standard introduces a way for contracts on the ZTP blockchain to explicitly declare the interfaces they support. This allows other contracts to interact seamlessly with them, by querying supported interfaces and adjusting their functionality accordingly.
Protocol Overview
Interface Function
Contracts implementing ZTP165 must include the following function:
functioninit(input_str) {let input =JSON.parse(input_str);Utils.assert(implementsInterface(OptimismMintableZTP20, IOptimismMintableZTP20),'OptimismMintableZTP20 does not implement IOptimismMintableZTP20');Utils.assert(implementsInterface(OptimismMintableZTP20,IZEP165),'OptimismMintableZTP20 does not implement IZEP165');returntrue;}
Usage
this.isOptimismMintableZTP20=function (token) {let interfaceId =utils.sha256(JSON.stringify(interfaceId),1);let queryInput = {'method':'supportsInterface','params': {'interfaceId': interfaceId } };let ret =Chain.contractQuery(token,JSON.stringify(queryInput));utils.assert(ret !==false,'Contract does not exist');if (ret.err ===null&&ret.error) {returnfalse; }returnJSON.parse(ret.result).data;