This site requires Javascript to be enabled.

Compiling a contract

In this section, we will download the code for a sample contract and compile it into a wasm binary executable.


Please refer to the Setting up environment guide to install the required dependencies before proceeding.

Download contract

Begin by downloading the cw-contracts repository. You will be compiling the nameservice contract.

Clone the repository:

git clone cw-contractsgit checkout maincd contracts/nameservice

Compile contract using rust-optimizer


You will need Docker installed and running in order to run rust-optimizer.

Navigate to the project root and run the following command:

docker run --rm -v "$(pwd)":/code \  --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \  cosmwasm/rust-optimizer:0.12.12

On Windows, you can run the following command instead from the root of your smart contract's project folder.

docker run --rm -v ${pwd}:/code `
 --mount type=volume,source="$("$(Split-Path -Path $pwd -Leaf)")_cache",target=/code/target `
 --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry `

This command will optimize the .wasm file and generate an optimized .wasm file in the artifacts directory.