We are glad to present the new contract binding generation in TypeScript language. We consider this as a major improvement in the way we are working with Archetype and Michelson contracts.
Completium CLI now provides a simple command to generate the TypeScript binding:
Contract binding refers here to a generated interface to interact with a contract (mainly call its entry points and retrieve data from its storage); this interface is expressed in a native language with native types (here TypeScript).
The main benefits are that it removes the burden of manipulating complex JSON structures of Micheline values; it also integrates well with IDE and, in the case of TypeScript, provides strong type checking at compilation time, rather than at execution time.
Consider the following Archetype contract:
The following code illustrates how to interact in TypeScript with this contract:
Note that the
msg storage element is retrieved with the dedicated
get_msg method of automatically generated binding object
exec entry point is called with the method with same name. Its signature is fully specified with native TS types:
The mapping from Archetype/Michelson types to TypeScript types is presented here.
The Archetype test framework has been totally redesigned to integrate the binding feature seamlessly.
The commands below creates an Node.js project in the
myproject directory and installs the required packages.
The command below generates the bindings for contracts found in
The test framework is presented in details here.
Binding is also available to integrate smart contracts in Dapps.
The command to generate the binding for integration in a DApp: