Cascadia
  • Welcome to Cascadia
    • Brand Guidelines
    • Official Links
  • Artificial Intelligence
    • Incentives
  • Developers
    • Addresses
    • CosmWasm
      • Smart Contracts
      • Install Requirements
      • Set your Environment
      • Optimization
      • Deployment
      • Multi-Chain Contracts
        • The Actor Model
      • CW1 Subkeys Contract
        • Guide
      • CW20 Base Contract
        • Guide
      • C721 Base Contract
        • Guide
      • Upload Contract
        • Create a WASM File
      • Sign and Verify
        • Guide
    • Solidity
      • Deployment
      • Verification
        • Block Explorer
        • Hardhat
  • Directory
    • Address
    • API
    • Applications
    • Explorer
    • Faucet
    • Genesis
    • Governance
    • GRPC
    • Guide
    • Peers
    • RPC
    • Snapshot
    • State Sync
    • Website
    • Websocket
  • Governance
    • Align
      • Cooldown Period
      • Functions
    • Off-Chain
    • On-Chain
      • Voting
    • Proposals
      • On-Chain Voting via CLI
      • Proposal (Example)
    • VeTokenomics
      • Model
      • Voting Power Calculation
    • Analytics
  • Network
    • ChainID & Address Prefix
    • Configuration
    • Consensus
    • Denomination
    • Distribution
      • Block Rewards
      • Gas Fees
    • ESG
    • Faucet
    • Modules
    • Parameters
    • Peers
  • Security
    • Disclosure Policy
    • Multisignature
  • Staking
    • Claim
    • Delegate
    • Manual
    • Redelegate
    • Undelegate
  • Use Cases
    • Business Development and Marketing
    • Consumer Relationship Management
  • Node
    • Cloud Platforms
      • Amazon Web Services
      • Google Cloud Platform
    • Snapshot
    • State-Sync
    • Upgrade
      • Automated
      • Manual
  • Validators
    • System Requirements
    • Installation
    • Reference
      • Customization
  • Community
    • Discord
    • Telegram
    • Twitter
  • Legal
    • Privacy Policy
    • Terms & Conditions
Powered by GitBook
On this page
Edit on GitHub
  1. Developers
  2. CosmWasm

Optimization

PreviousSet your EnvironmentNextDeployment

Last updated 1 year ago

Before progressing, ensure you've completed the first steps. It's important to have either the Node.js REPL or the wasmd Go CLI pre-configured.

Step 1: Obtaining and Compiling the Contract Code

Get the repository first. Then:

git clone https://github.com/InterWasm/cw-contracts
cd cw-contracts
git checkout main
cd contracts/nameservice
rustup default stable
cargo wasm

To trim it down, you can run:

RUSTFLAGS='-C link-arg=-s' cargo wasm

This command yields a much compact version, roughly 165kB in size. This file or another optimized version will eventually get uploaded to the blockchain.

Step 2: Running Unit Tests

Unit tests ensure the contract operates as expected:

RUST_BACKTRACE=1 cargo unit-test

Step 3: Optimizing for Deployment

The rust-optimizer is the tool for this task and it allows third parties to validate the legitimacy of the contract.

The rust-optimizer requires Docker.

On Linux and Mac, execute:

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.11

For Windows:

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 `
 cosmwasm/rust-optimizer:0.12.11

After optimization, the resultant binary is located under the artifacts directory and will be approximately 138 kB in size.

cw-contracts