Skip to content

Commit 6c34b19

Browse files
committed
add IDL docs
1 parent bd6b54d commit 6c34b19

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

docs/idl.md

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

0 commit comments

Comments
 (0)