OTP-002:合约 ABI
ABI 定义了如何与智能合约通信。 它包含有关合约接收器、数据结构等的信息。
动机
ABI 是一种重要工具,允许开发人员生成方便的绑定和用户界面等。 其中最好的消费者用例之一是使用DAO,并在签署交易之前能够确认它到底在尝试做什么。
指南
本 OTP 基于 TLB+ 中定义的类型,建议在阅读本 OTP 之前先了解这些类型。
技术说明
ABI 是一个 JSON 文件:
{ "name": "MyContract", "types": [ { "name": "MyRequest", "header": 12315123, "fields": [ { "name": "queryId", "type": { "kind": "simple", "type": "int", "optional": false, "format": "uint256" } } ] } ], "receivers": [ { "type": "binary", "kind": "internal", "name": "MyRequest" }, { "type": "binary", "kind": "internal" }, { "type": "comment", "kind": "internal", "comment": "Vote!" }, { "type": "comment", "kind": "internal" }, { "type": "empty", "kind": "internal" } ], "getters": [ { "name": "getOwner", "type": "address", "args": [] }, { "name": "getBalance", "type": "coins", "args": [ { "name": "invested", "type": { "kind": "simple", "type": "uint", "format": "coins" } } ] } ], "errors": { "123": "Error description", "124": "Division by zero" }}
缺点
- ABI 的二进制和紧凑表示法可能会更好,但目前并不重要。
现有技术
- OTP-001,是对本 OTP 的补充。