Skip to main content

Basic instructions

To compile release version of the smart contract you can run:

cargo build --target wasm32-unknown-unknown --release

Note: The above build command is setting a target flag to create a WebAssembly .wasm file.

Notice that your project directory now has a few additional items:

โ”œโ”€โ”€ Cargo.lock โŸต created during build to lock dependencies
โ”œโ”€โ”€ Cargo.toml
โ”œโ”€โ”€ src
โ”‚ โ””โ”€โ”€
โ””โ”€โ”€ target โŸต created during build, holds the compiled wasm

Build and Flags#

We recommend you to optimize your build artifact with the use of the next flags.

env 'RUSTFLAGS=-C link-arg=-s' cargo build --target wasm32-unknown-unknown --release

The above command is essentially setting special flags and optimizing the resulting .wasm file. At the end of the day, it's simply a customized cargo build --release command.

Windows users: please modify the above command as:

set RUSTFLAGS=-C link-arg=-s
cargo build --target wasm32-unknown-unknown --release

You can simpify this command by adding this flags to your ProjectFolder/.cargo/config.toml.

rustflags = ["-C", "link-arg=-s"]

You can find an example here.