The Problem
The prevailing solution to generating JS/TS code to communicate with your smart contracts is to generate JSON schemas with the cosmwasm-schema crate, then to generate TypeScript code from these schemas, e.g. using json-schema-to-typescript. This is an absolutely awful pipeline as it produces code that cannot properly capture the actual types, as JSON schemas simply cannot express the proper types. It has no awareness of serialized types. It makes no distinction between stringified numbers and serialized byte arrays. It has no idea if a stringified number is aUint256
or a Decimal
, or if a serialized byte array is in
hexadecimal or base64 encoding. We are losing type information, and thus need to re-insert it by
manually serializing and deserializing data according to our smart contract’s needs.
The Solution
Apophis already vastly simplifies smart contract messaging. The new solution will, just likecosmwasm-schema
, expose a generate_api!
macro that generates type declarations using mapped
original types in the smart contract rather than serialized types. The de/serialization middleware
of Apophis abstracts away the actual serialization, so as a smart contract developer you will rarely
need to actually know how to de/serialize your data, e.g. you can pass Coin
or bigint
s directly
into your messages.
Note that Apophis already handles de/serialization for you. This part is just about generating the
type declarations for convenience and better code maintainability.