|
| 1 | +# CosmWasm IDL v1.0.0 |
| 2 | + |
| 3 | +The CosmWasm IDL (Interface Description Language) is a format for describing the |
| 4 | +interface of a smart contract, meant to be consumed by generic clients. This |
| 5 | +allows those clients to interact with CosmWasm contracts without having any |
| 6 | +prior information about API endpoints. |
| 7 | + |
| 8 | +If you have a smart contract generated from the usual |
| 9 | +[template](https://github.com/CosmWasm/cw-template), you should be able to get |
| 10 | +an IDL file for it by simply running `cargo schema`. |
| 11 | + |
| 12 | +An example consumer of these files is |
| 13 | +[`ts-codegen`](https://github.com/CosmWasm/ts-codegen). |
| 14 | + |
| 15 | +The IDL's only representation is currently JSON-based. |
| 16 | + |
| 17 | +Currently, the IDL format uses [JSON schemas](https://json-schema.org/) heavily |
| 18 | +for defining messages and their responses, but provides some metadata and |
| 19 | +structure to tie them together. |
| 20 | + |
| 21 | +## An example |
| 22 | + |
| 23 | +The following is an overview with the JSON schemas removed. The full file can be |
| 24 | +found |
| 25 | +[here](https://github.com/CosmWasm/cosmwasm/blob/v1.5.3/contracts/hackatom/schema/hackatom.json). |
| 26 | + |
| 27 | +```json |
| 28 | +{ |
| 29 | + "contract_name": "hackatom", |
| 30 | + "contract_version": "0.0.0", |
| 31 | + "idl_version": "1.0.0", |
| 32 | + "instantiate": *JSON_SCHEMA_FOR_INSTANTIATE*, |
| 33 | + "execute": *JSON_SCHEMA_FOR_EXECUTE*, |
| 34 | + "query": *JSON_SCHEMA_FOR_QUERY*, |
| 35 | + "migrate": *JSON_SCHEMA_FOR_MIGRATE*, |
| 36 | + "sudo": *JSON_SCHEMA_FOR_SUDO*, |
| 37 | + "responses": { |
| 38 | + "get_int": *JSON_SCHEMA_FOR_RESPONSE_TO_GET_INT_QUERY*, |
| 39 | + "other_balance": *JSON_SCHEMA_FOR_RESPONSE_TO_OTHER_BALANCE_QUERY*, |
| 40 | + } |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +## Fields |
| 45 | + |
| 46 | +### _contract_name_, _contract_version_ |
| 47 | + |
| 48 | +Contract metadata. The name is not currently guaranteed to be unique. |
| 49 | + |
| 50 | +### _idl_version_ |
| 51 | + |
| 52 | +The version of the IDL format itself. This number adheres to |
| 53 | +[Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html). |
| 54 | + |
| 55 | +Using this version number, a client is advised to validate that the IDL files |
| 56 | +they're trying to parse are backwards compatible with the IDL version the client |
| 57 | +was developed against. |
| 58 | + |
| 59 | +For example, if you're developing a client against the `1.1.0` version of this |
| 60 | +spec, this client could accept IDL files for which |
| 61 | +`1.1.0 <= idl_version < 2.0.0` is true. |
| 62 | + |
| 63 | +Clients are expected to accept (and ignore) unknown fields. If new fields are |
| 64 | +added to the IDL format, this might be considered a backwards compatible change. |
| 65 | + |
| 66 | +### _instantiate_, _execute_, _query_, _migrate_, _sudo_ |
| 67 | + |
| 68 | +These are standard entrypoints a smart contract might have. Under these fields, |
| 69 | +an IDL file will directly embed a JSON schema for messages that could be passed |
| 70 | +to that particular entrypoint. |
| 71 | + |
| 72 | +Out of these, `instantiate` is the only mandatory field every smart contract is |
| 73 | +expected to set. The rest of them are optional and might not appear in every IDL |
| 74 | +file, meaning the smart contract does not have those entrypoints. |
| 75 | + |
| 76 | +### _responses_ |
| 77 | + |
| 78 | +The `responses` field is currently a dictionary mapping of query names to their |
| 79 | +response types. The response types are described by embedded JSON schema |
| 80 | +objects. |
| 81 | + |
| 82 | +### JSON Schema version |
| 83 | + |
| 84 | +TODO |
0 commit comments