Use Cw-orchestrator to speed-up your development
Integrate you smart-contract with cw-orch and facilitate testing/development and maintenance of your project.
Introduction
cw-orchestrator is the most advanced scripting, testing, and deployment framework for CosmWasm smart-contracts. It makes it easy to write cross-environment compatible code for cw-multi-test, Test Tube, Starship (alpha), and live networks, significantly reducing code duplication and test-writing time.
Get ready to change the way you interact with contracts and simplify you smart-contracts journey. The following steps will allow you to integrate cw-orch
and write clean code such as:
In this quick-start guide, we will review the necessary steps in order to integrate cw-orch
into a simple contract crate. We review integration of rust-workspaces (multiple contracts) at the end of this page.
NOTE: Quicker than the quick start
If you're moving quicker than everybody else, we suggest looking at a before-after review of this example integration. This will help you catch the additions you need to make to your contract to be able to interact with it using cw-orchestrator.
NOTE: If you want to go more in depth, browse the full
cw-orch
documentation.
Summary
Single Contract Integration
Throughout this example, we will be using cw-orch
to interact with a simple counter contract. All the steps below apply to any smart contract, no matter the complexity.
Adding cw-orch
to your Cargo.toml
file
cw-orch
to your Cargo.toml
fileTo use cw-orchestrator, you need to add cw-orch
to your contract's TOML file. Run the command below in your contract's directory:
Alternatively, you can add it manually in your Cargo.toml
file as shown below:
Now that we have added cw-orch
as an optional dependency we will want to enable it through a feature-flag. This ensures that the code added by cw-orch
is not included in the wasm artifact of the contract.
To do this add an interface
feature to the Cargo.toml
and enable cw-orch
when it is enabled like so:
NOTE: If you are using
rust-analyzer
, you can add the following two lines in yoursettings.json
to make sure the features get taken into account when checking the project:
Creating an Interface
When using a single contract, we advise creating an interface.rs
file inside your contract's directory. You then need to add this module to your lib.rs
file. Don't forget to feature-flag the module in order to be able to use cw-orch
inside it.
Then, inside that interface.rs
file, you can define the interface for your contract:
Learn more about the content of the interface creation specifics in the cw-orch
documentation
NOTE: It can be useful to re-export this struct to simplify usage (in
lib.rs
):
Interaction helpers
cw-orchestrator provides a additional macros that simplify contract calls and queries. The macro implements functions on the interface for each variant of the contract's ExecuteMsg
and QueryMsg
.
Enabling this functionality is very straightforward. Find your ExecuteMsg
and QueryMsg
definitions (in msg.rs
in our example) and add the ExecuteFns
and QueryFns
derive macros to them like below:
Find out more about the interaction helpers in the cw-orch
documentation
NOTE: Again, it can be useful to re-export these generated traits to simplify usage (in
lib.rs
):
Using the integration
Now that all the setup is done, you can use your contract in tests, integration-tests or scripts.
Start by importing your crate, with the interface
feature enabled. Depending on your use-case this will be in [dependencies]
or [dev-dependencies]
:
You can now use:
Integration in a workspace
In this paragraph, we will use the cw-plus
repository as an example. You can review:
The full integration code with
cw-orch
addedThe complete diff that shows you all integration spots (if you want to go fast)
Handling dependencies and features
When using workspaces, you need to do the 2 following actions on all crates that include ExecuteMsg
and QueryMsg
used in your contracts:
Add
cw-orch
as an optional dependencyAdd an
interface
feature (ensurescw-orch
is not compiled into yourwasm
contract)
Refer above to Adding cw-orch
to your Cargo.toml
file for more details on how to do that.
For instance, for the cw20_base
contract, you need to execute those 2 steps on the cw20-base
contract (where the QueryMsg
are defined) as well as on the cw20
package (where the ExecuteMsg
are defined).
Creating an interface crate
When using a workspace, we advise you to create a new crate inside your workspace for defining your contract's interfaces. In order to do that, use:
Add the interface package to your workspace Cargo.toml
file
Inside this interface
crate, we advise to integrate all your contracts 1 by 1 in separate files. Here is the structure of the cw-plus
integration for reference:
When importing your crates to get the messages types, you can use the following command in the interface folder. Don't forget to activate the interface feature to be able to use the cw_orch functionalities.
Integrating single contracts
Now that you workspace is setup, you can integrate with single contracts using the above section
More examples and scripts
You can find more example interactions on the counter-contract
example directly in the cw-orchestrator
repo:
Some examples showcase interacting with live chains.
Some other examples show how to use the library for testing your contracts.
FINAL ADVICE: Learn more and explorer our full
cw-orch
documentation !
Last updated