Compiling smart contracts

Location

All rust contract cargos are located in contracts/ directory. As contracts are written in Rust, all files containing contracts will have a file extension of .rs. Associated rust libraries will also have a .rs extension.

With a starter Houston project (created through houston init), you're given a single counter starter contract cargo to develop a cosmwasm smart contract. If you're using a Houston Cargo, you will have multiple files here.

Command

To compile a Houston project, change to the root of the directory where the project is located and run this command:

$ houston compile

Upon first run, all selected cargos in contracts/ directory will be compiled in wasm32-unknown-unknown environment, and all contract wasm files will be moved to wasm/ directory. Upon subsequent runs, Houston will compile the selected contracts that have been changed since the last compile and replace wasm binaries in wasm/ directory.

Wasm Binaries

Wasm binaries are the compiled binaries of smart contracts. They are located in wasm/ directory, and they are used to deploy contracts to Terra blockchain.

Schemas

Schemas are the JSON scheme that are needed to communicate with cosmwasm smart contracts.

These schemas are integral to the test scripts that interacts with smart contract, and they play important part to interact with contracts. *You should not edit* these files as these files are overwritten each compilation process as well as it is used to put arguments

Compiling contracts

Set current working directory inside of the project root directory then run:

houston compile [contract name]

All contract cargos in the contracts directory will be compiled if there is no input.

[contract name] is an optional parameter to specify which contract cargo to compile.

Once the operation is initiated, you'll see the event in the console as below:

After compilation of each contract, you'll get the directories for compiled results as below:

> WASM written to /Users/.../<project folder>/wasm
> Schemas written to /Users/.../<project folder>/schemas/<contract name>_schema

Compiled WASM binaries will be placed in wasm directory as <contract name>.wasm. Generated collection of schema abi json files will be placed in a directory with the name <contract name>-schema in schemas directory.

After successfully compiling the starter contract, you will have this new project structure with the following items:

myProject/
  |- contracts
  | |- starter
  |- wasm
  | |- starter.wasm
  |- schema
  | |- starter-schema
  |   |- config.json
  |   |- ....
  | migrations
  | |- 0_deploy_starter.ts
  | package.json
  | tsconfig.json

Last updated