Workspace cw-orch setup process

In all this tutorial, we will use the cw-plus package as an example. This repository is maintained by CosmWasm and contains standard contracts. It’s also a good workspace structure example.

Crate setup

If you are using multiple contracts in a single project, we advise you to centralize all the interfaces to your contracts in a single location. To do so, go inside your packages folder and create a new interface library crate:

cargo new interface --lib
cd interface

Then, going into this crate, we need to add cw-orch as a dependency:

cargo add cw-orch --package interface 

Individual contract interface

Now inside this crate, you can add the interfaces to all your contracts individually. A sane way to do so is to create a new file (also called module) for each contract. For instance, the interface folder in the cw-plus repository has the following structure:

.
├── Cargo.toml
└── src
    ├── cw1_subkeys.rs
    ├── cw1_whitelist.rs
    ├── cw20_base.rs
    ├── cw20_ics20.rs
    ├── cw3_fixed_multisig.rs
    ├── cw3_flex_multisig.rs
    ├── cw4_group.rs
    ├── cw4_stake.rs
    └── lib.rs

Inside each file, you can define your contract interface. You can find the tutorial for that in the dedicated Interfaces page.

Scripts

We advise using a scripts crate at the root of your workspace. This will help you centralize your scripts and have them easily accessible for eventual other users accessing your crate remotely. This crate should be a binary crate:

cargo new --bin scripts

Final project structure

Following the steps above, the directory structure should eventually look like this:

.
├── Cargo.toml
├── artifacts
│   ├── other_contract.wasm
│   └── my_contract.wasm
├── contracts
│   ├── my-contract
│   │   ├── Cargo.toml
│   │   └── src
│   │       ├── contract.rs (execute, instantiate, query, ...)
│   │       └── ..
│   └── other-contract
│       └── ..
├── packages
│   ├── my-project (messages)
│   │   ├── Cargo.toml
│   │   └── src
│   │       ├── lib.rs
│   │       ├── my-contract.rs
│   │       ├── other-contract.rs
│   │       └── ..
│   └── my-project-interface (interface collection, renamed here)
│       ├── Cargo.toml
│       └── src
│           ├── lib.rs
│           ├── my-contract.rs
│           ├── other-contract.rs
│           └── ..
└── scripts (executables)
    ├── .env
    ├── Cargo.toml
    └── src
        ├── deploy.rs
        └── test_project.rs

NOTE:

  • The artifacts folder is generated by the workspace-optimizer, and contains all your compiled contracts
  • We advise you to place your scripts inside the scripts crate to centralize them and facilitate retrieving them:

Now that the setup is complete, you can go back to the Contracts page to create the interfaces for your contracts one by one and start scripting/testing your contracts with ease.

You can also continue this tutorial and discover how to: